Last active
May 4, 2022 20:52
-
-
Save camisetags/12927f1edfec824be8e76efd7d57a041 to your computer and use it in GitHub Desktop.
chal
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
const inputA = 'AAAAAAAAAAAAABBCCCCDD' | |
function runLength(string) { | |
let result = ''; | |
let count = 1; | |
let current = string[0]; | |
for (let i = 1; i < string.length; i++) { | |
if (string[i] === current && count < 9) { | |
count++; | |
} else { | |
result += `${count}${current}`; | |
count = 1; | |
current = string[i]; | |
} | |
} | |
result += `${count}${current}`; | |
return result; | |
} | |
const outputA = '9A4A2B4C2D' | |
console.log(JSON.stringify(runLength(inputA)) === JSON.stringify(outputA)) |
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
let inputB = [1, 2, 3, 5, 6, 8, 9] | |
function squareSort(array) { | |
return array.map(num => num * num).sort((a, b) => a - b); | |
} | |
const outputB = [1, 4, 9, 25, 36, 64, 81] | |
console.log(JSON.stringify(squareSort(inputB)) === JSON.stringify(outputB)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment