Currently, I am working on optimizing the process of adding food and drink to an order simultaneously. To achieve this, I have created a promise that resolves when both actions are completed. These promises are then nested within another promise, which resolves when all orders are processed.
orders = [
{'name': 'john'},
{'name': 'sam'},
]
const p = orders.map((order) => {
return Promise.all([
add_food(order),
add_drink(order),
])
})
return Promise.all(p)
function add_food(order){
return Promise.resolve(order)
}
However, the issue I am facing is that the resulting array contains duplicated entries.
[
[ "order_1", "order_1"],
[ "order_2", "order_2"]
]
While this outcome is logical, I am looking for a solution to restructure the array to return:
[ "order_1", "order_1"]
Any suggestions on how to approach this problem?