Skip to content

Instantly share code, notes, and snippets.

@Vibhu-Agarwal
Created March 21, 2020 09:13
Show Gist options
  • Save Vibhu-Agarwal/a94fa79785406e728b185a66407334da to your computer and use it in GitHub Desktop.
Save Vibhu-Agarwal/a94fa79785406e728b185a66407334da to your computer and use it in GitHub Desktop.
Want to Successfully run test2
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