I’m not sure anymore if I’m going in right direction. I got stuck at the end of my code where i got my numbers multiplied. Is there a way to get them all in one array not every number seprate so I can sum them and finnish my function?
I don’t know any TypeScript, but …
You already have
for (let eachNum of allNums) {
let numPows = Math.pow(eachNum, numLength);
console.log(numPows);
}
If you just want the sum of numPows
from all the iterations,
you could have a varible that keeps track of the sum (declared outside the loop).
let total = 0
for (let eachNum of allNums) {
let numPows = Math.pow(eachNum, numLength);
total += numPows;
}
//console.log(total);
If you want an array of all the numPows
values, you could use .map
for the allNums
array.
let numPowsArray = allNums.map(eachNum => Math.pow(eachNum, numLength) );
1 Like