We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3ea3b07 commit 0bb92e4Copy full SHA for 0bb92e4
1 file changed
week4/homework/javascript_exercises/ex1-doubleEvenNumbers.test.js
@@ -0,0 +1,25 @@
1
+/*------------------------------------------------------------------------------
2
+Full description at: https://github.com/HackYourFuture/Homework/tree/main/1-JavaScript/Week4#exercise-1-the-odd-ones-out
3
+
4
+The `doubleEvenNumbers` function returns only the even numbers in the array
5
+passed as the `numbers` parameter and doubles them.
6
7
+Let's rewrite it (or _refactor_ it, as experienced developers would call it):
8
9
+- Using the `map` and `filter` functions, rewrite the function body of
10
+`doubleEvenNumbers`.
11
+------------------------------------------------------------------------------*/
12
+// ! Function to be tested
13
+function doubleEvenNumbers(numbers) {
14
+ const newNumbers = numbers.filter( number => number % 2 === 0)
15
+ .map( number => number * 2);
16
+ return newNumbers;
17
+}
18
19
+// ! Unit test (using Jest)
20
+test('doubleEvenNumbers should take the even numbers and double them', () => {
21
+ const actual = doubleEvenNumbers([1, 2, 3, 4]);
22
+ const expected = [4, 8];
23
+ expect(actual).toEqual(expected);
24
+});
25
0 commit comments