JSFiddle - React, Tailwind, and code Playground
JavaScript
/*nums = [2 5 3 7]
result = []
result.push {x:nums[0]}
for n in nums.slice(1)
result.push {n:n + result[-1].x}
log result
# [{x:2} {x:7} {x:10} {x:17}]
*/
var nums = [2,5,3,7];
var createObject = function(nums){
var result = [],
total = 0;
for(var i = 0; i < nums.length; i++){
total += nums[i];
result.push({"x": total});
}
return result;
};
console.log(createObject(nums));