let userInput = ["1 6 7 9 12 15", 12,16,15,34,28,2];
I’ve given array like above.
The result I want is to sum the elements of an array by index matching string elements and return the sum arrays.
The output:
[ 13, 22, 22, 43, 40, 17 ]
More optimised results are better.
let userInput = ["1 6 7 9 12 15", 12,16,15,34,28,2];
let stringArray = userInput[0].split(' ');
let stringTonum = stringArray.map(item => parseInt(item));
let sumArray = stringTonum.map((item, index)=>{return item + userInput[index+1]});
console.log(sumArray)