Created
March 21, 2020 09:13
-
-
Save Vibhu-Agarwal/a94fa79785406e728b185a66407334da to your computer and use it in GitHub Desktop.
Want to Successfully run test2
This file contains 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
const calculate = k => new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve(k**3) | |
}, 500) | |
}) | |
const gimme_val = async (k) => { | |
transformed_val = await calculate(k) | |
return transformed_val | |
} | |
// async function do_test1() { | |
// my_pre_built_array = [1, 2, 3] | |
// my_arr = [] | |
// for(index = 0; index < my_pre_built_array.length; index++) | |
// { | |
// transformed_val = await gimme_val(my_pre_built_array[index]) | |
// my_arr.push(transformed_val) | |
// } | |
// return my_arr | |
// } | |
// do_test1().then(new_array => console.log(new_array)) | |
function do_test2() { | |
my_pre_built_array = [1, 2, 3] | |
my_arr = [] | |
for(index = 0; index < my_pre_built_array.length; index++) | |
{ | |
gimme_val(my_pre_built_array[index]) | |
.then(transformed_val => { | |
my_arr.push(transformed_val) | |
}) | |
.catch(e => console.log(e)) | |
} | |
return my_arr | |
} | |
new_array = do_test2() | |
console.log(new_array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment