Created
June 28, 2017 16:59
-
-
Save ycmjason/0d6989b2db332f0954bbc0272b21aa0e to your computer and use it in GitHub Desktop.
Haskell's foldl1 equivalent in Javascript
This file contains hidden or 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
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