Skip to content

Instantly share code, notes, and snippets.

@iamFIREcracker
Forked from w33ble/index.js
Created August 28, 2024 10:27
Show Gist options
  • Save iamFIREcracker/2912b9b5ab583190d56ab33f1943099e to your computer and use it in GitHub Desktop.
Save iamFIREcracker/2912b9b5ab583190d56ab33f1943099e to your computer and use it in GitHub Desktop.
native promise mapSeries implementation
function mapSeries(arr) {
if (!Array.isArray(arr)) throw new Error('mapSeries requires an Array');
const length = arr.length;
const results = new Array(length);
arr.reduce((chain, item, i) => {
return chain.then(() => item).then(val => results[i] = val);
}, Promise.resolve())
.then(() => results);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment