Q:

Write a JavaScript program to get the sum of the powers of all the numbers from start to end (both inclusive)

0

Write a JavaScript program to get the sum of the powers of all the numbers from start to end (both inclusive).

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const sumPower = (end, power = 2, start = 1) =>
  Array(end + 1 - start)
    .fill(0)
    .map((x, i) => (i + start) ** power)
    .reduce((a, b) => a + b, 0);

console.log(sumPower(10));
console.log(sumPower(10, 3));
console.log(sumPower(10, 3, 5));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now