Files
30-seconds-of-code/snippets_archive/squareSum.md
Angelos Chalaris ade6be6cd7 Update squareSum.md
2018-10-16 13:55:06 +03:00

14 lines
365 B
Markdown

### squareSum
Squares each number in an array and then sums the results together.
Use `Array.prototype.reduce()` in combination with `Math.pow()` to iterate over numbers and sum their squares into an accumulator.
```js
const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0);
```
```js
squareSum(1, 2, 2); // 9
```