From 92377cf71af628cb5ea6b28ff7d6fa66a9b52449 Mon Sep 17 00:00:00 2001 From: Mainak Debnath <55401423+mainak-debnath@users.noreply.github.com> Date: Sun, 26 Jul 2020 22:39:46 +0530 Subject: [PATCH] fix(learn) : Changed language and added a test for Project euler problem-2 (#39221) * Edited wording in a test * Rearranged the tests Co-authored-by: Oliver Eyton-Williams --- ...roblem-2-even-fibonacci-numbers.english.md | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/curriculum/challenges/english/10-coding-interview-prep/project-euler/problem-2-even-fibonacci-numbers.english.md b/curriculum/challenges/english/10-coding-interview-prep/project-euler/problem-2-even-fibonacci-numbers.english.md index 1f6e7d952d..67985b544a 100644 --- a/curriculum/challenges/english/10-coding-interview-prep/project-euler/problem-2-even-fibonacci-numbers.english.md +++ b/curriculum/challenges/english/10-coding-interview-prep/project-euler/problem-2-even-fibonacci-numbers.english.md @@ -7,6 +7,7 @@ forumTopicId: 301838 --- ## Description +
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: @@ -14,22 +15,31 @@ Each new term in the Fibonacci sequence is generated by adding the previous two
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed n, find the sum of the even-valued terms. +
## Instructions +
## Tests +
```yml tests: - text: fiboEvenSum(10) should return a number. testString: assert(typeof fiboEvenSum(10) === 'number'); + - text: Your function should return an even value. + testString: assert.equal(fiboEvenSum(10) % 2 === 0, true); + - text: 'Your function should sum the even-valued Fibonacci numbers: fiboEvenSum(8) should return 10.' + testString: assert.strictEqual(fiboEvenSum(8), 10); - text: fiboEvenSum(10) should return 10. testString: assert.strictEqual(fiboEvenSum(10), 10); + - text: fiboEvenSum(34) should return 44. + testString: assert.strictEqual(fiboEvenSum(34), 44); - text: fiboEvenSum(60) should return 44. testString: assert.strictEqual(fiboEvenSum(60), 44); - text: fiboEvenSum(1000) should return 798. @@ -38,14 +48,12 @@ tests: testString: assert.strictEqual(fiboEvenSum(100000), 60696); - text: fiboEvenSum(4000000) should return 4613732. testString: assert.strictEqual(fiboEvenSum(4000000), 4613732); - - text: Your function should return an even value. - testString: assert.equal(fiboEvenSum(10) % 2 === 0, true); - ```
## Challenge Seed +
@@ -61,20 +69,20 @@ fiboEvenSum(10);
- -
## Solution -
+
```js const fiboEvenSum = (number) => { if (number <= 1) { return 0; } else { - let evenSum = 0, prevFibNum = 1, fibNum = 2; // According to problem description our Fibonacci series starts with 1, 2 + let evenSum = 0, + prevFibNum = 1, + fibNum = 2; // According to problem description our Fibonacci series starts with 1, 2 for (let i = 2; fibNum <= number; i++) { if (fibNum % 2 == 0) { evenSum += fibNum; @@ -83,7 +91,7 @@ const fiboEvenSum = (number) => { } return evenSum; } -} +}; ```