Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const reduce = (array = [], accumulator = {}) => {
- const iterate = index => accumulator => {
- const fn = array[index]
- const next = iterate(index + 1)
- return fn ?
- Promise.resolve(fn(accumulator, next)) :
- Promise.resolve(accumulator)
- }
- try {
- return iterate(0)(accumulator)
- } catch (ex) {
- return Promise.reject(ex)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement