Update squareSum.md

This commit is contained in:
Angelos Chalaris
2018-10-15 12:17:08 +03:00
committed by GitHub
parent 65ec33638e
commit fad13712d2

View File

@ -1,15 +1,15 @@
### squareSum
Squares each number passed into it and then sums the results together.
Squares each number in an array and then sums the results together.
Use `Array.prototype.reduce()` to iterate over numbers and to declare an accumulater.
Use `Array.prototype.reduce()` to iterate over numbers and to declare an accumulator.
Use `Math.pow()` to calculate power of each number and add all numbers into acculmulator.
```js
const squareSum = (arr) => arr.reduce((squareSum, number) =>
squareSum + Math.pow(number, 2), 0);
squareSum + Math.pow(number, 2), 0);
```
```js
squareSum([1, 2, 2]); // 9
```
```