Created
August 21, 2022 20:43
-
-
Save pfftdammitchris/9d2b2eb6ea4acb17d16d134b4c1c55c7 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, callback) { | |
const results = [] | |
for (let index = 0; index < arr.length; index++) { | |
const item = arr[index] | |
// The promise ends up here. But this time we save the result inside our final collection that is being returned after the loop is finished | |
const result = callback(item) | |
results.push(result) | |
} | |
return results | |
} | |
async function start() { | |
const arr = ['1', 2, 3, 'hello'].map((item) => Promise.resolve(item)) | |
const newArr = await Promise.all(map(arr, (item) => item)) | |
console.log(newArr) | |
} | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment