Posts

Showing posts from September, 2017

Javascript snippets

Posting more for self reference but hopefully it'll be useful for others too. :) Left-pad string with character 'c': String.prototype.padZero= function(len, c){ var s= this, c= c || '0'; while(s.length< len) s= c+ s; return s; } (Credit: kennebec from stackoverflow: convert '1' to '0001' in JavaScript .) Convert numbers between different bases (built in Javascript function): parseInt(<number>, <baseFrom>).toString(<baseTo>) Examples: parseInt("12", 10).toString(16); // returns "c" parseInt("1011", 2).toString(10); // returns 11 (Credit: faisalman from GitHubGist: baseConverter.js .)