Fix "hint" code not working for the challenge: "Sum All Odd Fibonacci Numbers" (#28676)
* Fix code not passing on challenge tests The code was not passing the challenge tests because we must sum only odd numbers. Cince we didn't provided an initial value for reduce, it would use the first element of the array, and if it was an odd number, it would skip our validation and add it to the final result. [https://www.freecodecamp.org/forum/t/sum-all-odd-fibonacci-numbers-solution-not-passing-all-tests/236058](https://www.freecodecamp.org/forum/t/sum-all-odd-fibonacci-numbers-solution-not-passing-all-tests/236058) * Same English fixed for Arabic * Same English fix for Chinese * Same English fix for Portuguese * Same English fix for Russian * Same English fix for Spanish
This commit is contained in:
@@ -93,14 +93,14 @@ function sumFibs(num) {
|
||||
// Sum only the odd numbers and return the value
|
||||
return arrFib.reduce((acc, curr) => {
|
||||
return acc + curr * (curr % 2);
|
||||
});
|
||||
}, 0);
|
||||
}
|
||||
|
||||
// test here
|
||||
sumFibs(4);
|
||||
```
|
||||
|
||||
 [运行代码](https://repl.it/@kr3at0/SumAllOddFibonacciNumbers)
|
||||
 [运行代码](https://repl.it/repls/ImpassionedFineConnection)
|
||||
|
||||
### 代码说明:
|
||||
|
||||
@@ -121,4 +121,4 @@ function sumFibs(num) {
|
||||
* 将解决方案分为以下类别之一 - **基本** , **中级**和**高级** 。 
|
||||
* 如果您添加了任何**相关的主要内容,**请仅添加您的用户名。 (  **_不要_** _删除任何现有的用户名_ )
|
||||
|
||||
> 看到 [**`Wiki Challenge Solution Template`**](http://forum.freecodecamp.com/t/algorithm-article-template/14272)供参考。
|
||||
> 看到 [**`Wiki Challenge Solution Template`**](http://forum.freecodecamp.com/t/algorithm-article-template/14272)供参考。
|
||||
|
Reference in New Issue
Block a user