Created
December 8, 2020 19:36
-
-
Save danielcodes/22cad763cf0b142ad84094171951ce10 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
// problem 2 | |
function lookAndSay(seq) { | |
let ans = []; | |
let start = 0; | |
while (start < seq.length) { | |
curr = seq[start]; | |
step = start; | |
while (step < seq.length) { | |
if (curr != seq[step]) { | |
break; | |
} | |
step += 1; | |
} | |
let count = step - start; | |
ans.push([count, curr]); | |
start = step; | |
} | |
return ans; | |
} | |
const sequences = [[1], [1, 1], [2, 1], [1, 2, 1, 1]]; | |
for(let i=0; i<sequences.length; i++){ | |
console.log(lookAndSay(sequences[i])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment