Skip to content

Instantly share code, notes, and snippets.

@ycmjason
Created June 28, 2017 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycmjason/0d6989b2db332f0954bbc0272b21aa0e to your computer and use it in GitHub Desktop.
Save ycmjason/0d6989b2db332f0954bbc0272b21aa0e to your computer and use it in GitHub Desktop.
Haskell's foldl1 equivalent in Javascript
function foldl(arr, f){
return arr.reduce((arr, x, i) => {
if(i === 0) return [x];
return arr.concat([f(arr[i - 1], x)]);
}, []);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment