Last active
December 5, 2022 23:14
-
-
Save benjaminparnell/e43ff69e06219221d0dc066d3ddcabb6 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
| function map (arr, fn, ctx = this) { | |
| return Promise.all(arr.map((item, index) => { | |
| return new Promise((resolve, reject) => { | |
| fn.call(ctx, item, index, arr, resolve, reject) | |
| }) | |
| })) | |
| } | |
| var arr = [1, 2, 3] | |
| map(arr, (item, index, arr, resolve, reject) => { | |
| setTimeout(function () { | |
| resolve(item * 2) | |
| }, item * 500) | |
| }) | |
| .then((values) => { | |
| console.log(values) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment