Skip to content

Instantly share code, notes, and snippets.

View razashoaib's full-sized avatar

Syed Shoaib Abidi razashoaib

View GitHub Profile
@razashoaib
razashoaib / look-and-say.js
Created December 16, 2017 10:13
Look and say sequence in javascript.
function lookAndSay(number) {
var regex = /(.)\1*/g;
return number.toString().replace(regex, function(regexMatch) {
return regexMatch.length.toString() + regexMatch.substring(0, 1);
});
}
// Usage
function init() {
var number = 1;
@razashoaib
razashoaib / base-conversion-with-dictionary-mapping.js
Last active December 16, 2017 10:17
Convert decimal number to any base and map the result to pre-defined dictionary.
// Convert decimal number to desired base and convert the result to it's respective alphabets from the dictionary.
function convertBaseFromDecimal(number, desiredBase) {
var num = number;
var rem = 0;
var convertedNumber = [];
// NOTE: Modify dictionary if desiredBase != 5
var dict = {
0 : "a",