Skip to content

Instantly share code, notes, and snippets.

@mindplace
Created March 29, 2016 14:38
Show Gist options
  • Select an option

  • Save mindplace/3877aa922f0c537b5c3e to your computer and use it in GitHub Desktop.

Select an option

Save mindplace/3877aa922f0c537b5c3e to your computer and use it in GitHub Desktop.
function lookSaySequence(num) {
var num = num.toString().split("");
var counters = [];
for (var i=0; i < num.length; i++) {
if (num[i] === num[i - 1]) {
continue;
}
var current = num[i];
var counter = 1;
var j = i + 1
while (current === num[j]) {
counter += 1;
j += 1;
}
counters.push(counter);
counters.push(current);
}
return (counters.join(""));
}
console.log(lookSaySequence(11342556) === "211314122516") // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment