Created
June 12, 2018 13:55
-
-
Save itacirgabral/3807d66141aca1ad3798737cac55c133 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
const reduce = iterable => function* reducerable (fn, s0) { | |
let acc = s0 | |
for (const i of iterable) { | |
yield acc = fn(i, acc) | |
} | |
} | |
export default reduce |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/*
import 'reduce' from './reducerable.js'
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
const redarr = reduce(arr)
const itedar = redarr((acc, last) => acc + last, 0)
for (const i of itedar) {
console.log(i)
}
*/