Wednesday 29 May 2019

I need a help resolving promise

I am getting output like[ [ Promise { 30 }, Promise { 18 }, Promise { 10 } ],[ Promise { 50 }, Promise { 10 }, Promise { 18 } ],[ Promise { 20 }, Promise { 14 }, Promise { 10 } ] ]​but want it to be like[[30,18,10],[50,10,18]]let destinations = [[{ origin: 19, destination: 11 },{ origin: 11, destination: 7 },{ origin: 7, destination: 3 }],[{ origin: 19, destination: 31 },{ origin: 3, destination: 7 },{ origin: 7, destination: 11 }],[{ origin: 19, destination: 1 },{ origin: 11, destination: 3 },{ origin: 3, destination: 7 }]]let promisesArray = destinations.map(destination => {return (destination.map(obj => {return new Promise((resolve, reject) => {findDifference(obj).then(data => resolve(data))})}))})Promise.all(promisesArray).then(function (results) {console.log(results)}).catch(function (error) {console.log(error)})​function findDifference(obj) {return new Promise((resolve, reject) => {resolve(obj.origin + obj.destination)})}

Submitted May 29, 2019 at 03:11PM by hightek11

No comments:

Post a Comment