Posts

Showing posts from November, 2019

Finding Partitions of a number

So recently i got a question from my friend Sameera who had this requirement.  Given a number N , he wanted to generate all possible combinations of n1,n2 where n1 + n2 = N For example if i give you 25 , you should output : 1,24 2,23 3,22 4,21 5,20 6,19 7,18 9,16 10,15 11,14 12,13 But he had an additional condition as well , these number pairs should not contain  an addition which involves a carry  .  ( As a non native English speaker this is the first time i even heard that word :) ) So that means in the above example if i gave you 25 , you should only output: 1,24 2,23 3,22 4,21 5,20 10,15 11,14 12,13 Notice that i have left out  6,19 7,18 9,16 Because adding them involves transferring 1 digit from one place to another. ( Please excuse my language as i am not a mathematician or well versed in maths so im trying to explain this in layman idiot terms here ). Ok , so in addition to the above mentioned

Sending a POST request in Simple Javascript

So recently i wanted to send a POST request to one of my backends using only simple plain Javascript. Found this code on Quora which worked nicely. Code : xhr = new XMLHttpRequest (); var url = "url" ; xhr . open ( "POST" , url , true ); xhr . setRequestHeader ( "Content-type" , "application/json" ); xhr . onreadystatechange = function () { if ( xhr . readyState == 4 && xhr . status == 200 ) { var json = JSON . parse ( xhr . responseText ); console . log ( json . email + ", " + json . name ) } } var data = JSON . stringify ({ "email" : "tomb@raider.com" , "name" : "LaraCroft" }); xhr . send ( data );

How to Debug NodeJs Easily

Found this great article on how to easily debug NodeJs using VSCode https://medium.com/the-node-js-collection/debug-your-node-js-app-in-60-seconds-9ee942a453f0