I'm playing around with some functions and I noticed that these two functions seem to have different outputs in a pure function. Am I right in thinking that these two outputs are different?
counter = 0;
function createObject1(name, calories, fat, carbs, protein) {
counter += 1;
return { id: counter, name, calories, fat, carbs, protein };
}
function createObject2(...args) {
counter += 1;
var data = {};
data['id'] = counter;
var headers = args[args.length - 1];
for (var i = 0; i < args.length-1; i++) {
data[headers[i]] = args[i]
}
return data
}
// How I'm calling them
createObject1('Cupcake', 305, 3.7, 67, 4.3);
createObject2('Cupcake', 305, 3.7, 67, 4.3, ["name","calories","fat","carbs","protein"]);
Thanks for your help! :-)
createObject2(1,2,3,4,5, ['name', 'calories', 'fat', 'carbs', 'protein']);