Created
October 12, 2021 15:46
-
-
Save karol-majewski/890904542baf92242c31e3d7230edfa4 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
type NonEmptyArray<T> = [T, ...T[]]; | |
const names: NonEmptyArray<string> = ['Sheldon', 'Leonard', 'Penny', 'Rajesh', 'Howard']; | |
function main(names: NonEmptyArray<string>, n: number){ | |
let index = n - 1; | |
while (index >= names.length) { | |
index = Math.floor((index - names.length) / 2); | |
} | |
return names[index]; | |
} | |
console.log( | |
main(names, 1), | |
main(names, 52), | |
main(names, 7230702951) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment