Steps:Get AMOUNT from a call to API endpoint /a, e.g. AMOUNT == 5 (in the code it is set to 2)Use this AMOUNT to make AMOUNT calls to endpoint /b receiving JSONResult might be: [{a: 1, b: 2}, {...}, {...}, {...}, {...}]Use this AMOUNT to make AMOUNT calls to endpoint /c receiving JSONResult might be: [{c: 3, d: 4}, {...}, {...}, {...}, {...}]Merge such that there is a resulting array of JSON objectsResult might be: [{a:1, b:2, c: 3, d: 4}, {...}, {...}, {...}, {...}]So pretty much it looks like this:          a           / \        b   c         \ /        resultI'm really trying to understand how to write nice NodeJS code (coming from Python), so I'm specifically looking for the most elegant way to do this. I hope people can give advice on my current code below, as well as perhaps just suggesting different though clearly better methods. E.g. doing everything in async but still merging into the same result.I'm also interested in which of the 3 styles of options (1/2/3) is best for writing NodeJS apps.Promise = require(bluebird);u = require(underscore)function get_phase_count() {    return new Promise(function(resolve, reject) {        resolve(2); // AMOUNT == 2    });}function get_phase_info(amount) {    console.log(amount) // this would be used but now it is mocked    return new Promise(function(resolve, reject) {        // note that I got this AMOUNT calls solved to deliver this        resolve([ { a: 1, b: 2 }, { a: 1, b: 2 } ]);    });}function get_phase_votes(amount) {    console.log(amount) // this would be used but now it is mocked    return new Promise(function(resolve, reject) {        // note that I got this AMOUNT calls solved to deliver this        resolve([ { c: 3, d: 4 }, { c: 3, d: 4 } ]);    });}function join_phase_promises(p1, p2) {    return Promise.all([p1, p2]);};Using those functions I wrote 3 style options:// Option 1get_phase_count().then(function(amount) {    join_phase_promises(get_phase_info(amount), get_phase_votes(amount)).then(function(args) {        console.log(u.map(u.zip(args[0], args[1]), function(x) {return u.extend(x[0], x[1])}));    })});// Option 2get_phase_count().then(function(amount) {    return join_phase_promises(get_phase_info(amount), get_phase_votes(amount));}).then(function(args) {    console.log(u.map(u.zip(args[0], args[1]), function(x) {return u.extend(x[0], x[1])}));})// Option 3get_phase_count().then(function(amount) {    return join_phase_promises(get_phase_info(amount), get_phase_votes(amount));}).then(function(args) {    console.log(u.map(u.zip(args[0], args[1]), function(x) {return u.extend(x[0], x[1])}));})
Parallel computation to be merged, depending on single call
javascript;node.js;promise;callback