add snippet

This commit is contained in:
Saqib Saghir
2018-10-15 11:53:12 +03:00
parent 60e4d3895f
commit 65ec33638e

View File

@ -0,0 +1,15 @@
### squareSum
Squares each number passed into it and then sums the results together.
Use `Array.prototype.reduce()` to iterate over numbers and to declare an accumulater.
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);
```
```js
squareSum([1, 2, 2]); // 9
```