Created
February 26, 2014 15:18
-
-
Save Visgean/9231368 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function make_groups(str){ | |
// makes an array of strings, for example aabb -> [[2,'a'], [2,'b']] | |
var boundaries = []; | |
var groups = []; | |
var current_letter = null | |
for (var i = 0, len = str.length; i < len; i++) { | |
if (str[i] !== current_letter){ | |
current_letter = str[i]; | |
boundaries.push(i); | |
} | |
} | |
boundaries.push(str.length) // limit of the last boundary needs upper limit | |
for (var i=0, len = boundaries.length -1; i < len; i++){ | |
n_of_elements = boundaries[i+1] - boundaries[i]; | |
groups.push([n_of_elements, str[boundaries[i]]]); | |
} | |
return(groups); | |
}; | |
function lookSay(number){ | |
var groups = make_groups(String(number)); | |
var final_string = []; | |
for (var i=0, len = groups.length; i < len; i++){ | |
final_string.push(groups[i][0]); | |
final_string.push(groups[i][1]); | |
} | |
number = final_string.join(''); | |
return Number(number); | |
}; | |
lookSay(122); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment