# Sum of powers in range

Calculates the sum of the powers of all the numbers from `start` to `end` (both inclusive).

```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);

sumPower(10); // 385
sumPower(10, 3); // 3025
sumPower(10, 3, 5); // 2925```

## More like this

• JavaScript ·

### Generate a JavaScript array of random integers in a given range

Combining `Math.random()` and a few simple math operations, you can generate an array of random integers in a specified range.

• JavaScript ·

### Clamp or map a number to a range in JavaScript

Clamping and mapping a number to a range are two common and easily confused operations. Learn how to perform each in JavaScript.

• JavaScript ·

### Generate a random number or integer in a range with JavaScript

Enhance JavaScript's `Math.random()` to generate a random number or integer in a specified range.

• JavaScript ·

### Number in range

Checks if the given number falls within the given range.

Start typing a keyphrase to see matching snippets.