Created
March 29, 2016 14:38
-
-
Save mindplace/3877aa922f0c537b5c3e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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