Remove squareSum
This commit is contained in:
@ -1,16 +0,0 @@
|
||||
---
|
||||
title: squareSum
|
||||
tags: math,beginner
|
||||
---
|
||||
|
||||
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
|
||||
```
|
||||
@ -1,16 +0,0 @@
|
||||
const {squareSum} = require('./_30s.js');
|
||||
|
||||
test('squareSum is a Function', () => {
|
||||
expect(squareSum).toBeInstanceOf(Function);
|
||||
});
|
||||
test('squareSum returns the proper result', () => {
|
||||
expect(squareSum(2, 3, 4)).toBe(29);
|
||||
});
|
||||
|
||||
test('works with negative numbers', () => {
|
||||
expect(squareSum(-2, 3, -4)).toBe(29);
|
||||
});
|
||||
|
||||
test('NaN when parameters have text', () => {
|
||||
expect(squareSum(-2, 3, -4, 'text')).toBe(NaN);
|
||||
});
|
||||
Reference in New Issue
Block a user