forked from HackYourFuture/Assignments
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathex1-doubleEvenNumbers.test.js
More file actions
27 lines (23 loc) · 1.07 KB
/
ex1-doubleEvenNumbers.test.js
File metadata and controls
27 lines (23 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*------------------------------------------------------------------------------
Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week4#exercise-1-the-odd-ones-out
The `doubleEvenNumbers` function returns only the even numbers in the array
passed as the `numbers` parameter and doubles them.
Let's rewrite it (or _refactor_ it, as experienced developers would call it):
- Using the `map` and `filter` functions, rewrite the function body of
`doubleEvenNumbers`.
------------------------------------------------------------------------------*/
// ! Function to be tested
function doubleEvenNumbers(numbers) {
// TODO rewrite the function body using `map` and `filter`.
return numbers
.filter((number) => number % 2 === 0)
.map((number) => number * 2);
}
// ! Unit test (using Jest)
describe('js-wk3-ex1-doubleEvenNumbers', () => {
test('doubleEvenNumbers should take the even numbers and double them', () => {
const actual = doubleEvenNumbers([1, 2, 3, 4]);
const expected = [4, 8];
expect(actual).toEqual(expected);
});
});