Created
January 7, 2017 16:48
-
-
Save dignifiedquire/dd08d2f3806a7b87f45b00c41fe109b7 to your computer and use it in GitHub Desktop.
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
'use strict' | |
const expect = require('chai').expect | |
function mapSeries (list, func) { | |
const res = [] | |
return list.reduce((acc, next) => { | |
return acc.then((val) => { | |
res.push(val) | |
return func(next) | |
}) | |
}, Promise.resolve(null)).then((val) => { | |
res.push(val) | |
return res.slice(1) | |
}) | |
} | |
describe.only('map', () => { | |
it('maps', () => { | |
const hashes = [ | |
'hash1', | |
'hash2', | |
'hash3' | |
] | |
const get = (hash) => Promise.resolve(hash + 'cool') | |
return mapSeries(hashes, get).then((res) => { | |
expect(res).to.be.eql([ | |
'hash1cool', | |
'hash2cool', | |
'hash3cool' | |
]) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment