Created
June 6, 2021 08:39
-
-
Save jocrah/155024fafcea5fdaa5cb16735a685815 to your computer and use it in GitHub Desktop.
Haskell inits in js (cassidy newsletter)
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 inits = (inputArray) => { | |
const result = [] | |
for (let i = 0; i <= inputArray.length; i++) { | |
result.push(inputArray.slice(0,i)) | |
} | |
return result | |
} | |
const output = inits([1,2,3,4]) | |
console.log(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice one, thanks for sharing!!!