Skip to content

Instantly share code, notes, and snippets.

@jocrah
Created June 6, 2021 08:39
Show Gist options
  • Save jocrah/155024fafcea5fdaa5cb16735a685815 to your computer and use it in GitHub Desktop.
Save jocrah/155024fafcea5fdaa5cb16735a685815 to your computer and use it in GitHub Desktop.
Haskell inits in js (cassidy newsletter)
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)
@jakazzy
Copy link

jakazzy commented Jun 7, 2021

Nice one, thanks for sharing!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment