Skip to content

Instantly share code, notes, and snippets.

@itacirgabral
Created June 12, 2018 13:55
Show Gist options
  • Save itacirgabral/3807d66141aca1ad3798737cac55c133 to your computer and use it in GitHub Desktop.
Save itacirgabral/3807d66141aca1ad3798737cac55c133 to your computer and use it in GitHub Desktop.
const reduce = iterable => function* reducerable (fn, s0) {
let acc = s0
for (const i of iterable) {
yield acc = fn(i, acc)
}
}
export default reduce
@itacirgabral
Copy link
Author

/*
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)
}
*/

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