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:
ghukahr
2019-02-12 21:54:53 -02:00
committed by Randell Dawson
parent 72db776a71
commit dcc1397c0c
6 changed files with 17 additions and 17 deletions

View File

@ -93,14 +93,14 @@ localeTitle: Sum All Odd Fibonacci Numbers
// Sum only the odd numbers and return the value // Sum only the odd numbers and return the value
return arrFib.reduce((acc, curr) => { return arrFib.reduce((acc, curr) => {
return acc + curr * (curr % 2); return acc + curr * (curr % 2);
}); }, 0);
} }
// test here // test here
sumFibs(4); sumFibs(4);
` `
![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ":صاروخ:") [تشغيل الكود](https://repl.it/@kr3at0/SumAllOddFibonacciNumbers) ![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ":صاروخ:") [تشغيل الكود](https://repl.it/repls/ImpassionedFineConnection)
### شرح الشفرة: ### شرح الشفرة:

View File

@ -93,14 +93,14 @@ function sumFibs(num) {
// Sum only the odd numbers and return the value // Sum only the odd numbers and return the value
return arrFib.reduce((acc, curr) => { return arrFib.reduce((acc, curr) => {
return acc + curr * (curr % 2); return acc + curr * (curr % 2);
}); }, 0);
} }
// test here // test here
sumFibs(4); sumFibs(4);
``` ```
![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ":火箭:") [运行代码](https://repl.it/@kr3at0/SumAllOddFibonacciNumbers) ![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ":火箭:") [运行代码](https://repl.it/repls/ImpassionedFineConnection)
### 代码说明: ### 代码说明:

View File

@ -92,13 +92,13 @@ As you get the next odd one, don't forget to add it to a global variable that ca
// First, reverse the array to avoid starting acc with the first/greater number when it's even // First, reverse the array to avoid starting acc with the first/greater number when it's even
return arrFib.reverse().reduce((acc, curr) => { return arrFib.reverse().reduce((acc, curr) => {
return acc + curr * (curr % 2); return acc + curr * (curr % 2);
}); }, 0);
} }
// test here // test here
sumFibs(4); sumFibs(4);
![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ":rocket:") <a href='https://repl.it/@kr3at0/SumAllOddFibonacciNumbers' target='_blank' rel='nofollow'>Run Code</a> ![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ":rocket:") <a href='https://repl.it/repls/ImpassionedFineConnection' target='_blank' rel='nofollow'>Run Code</a>
### Code Explanation: ### Code Explanation:

View File

@ -93,14 +93,14 @@ function sumFibs(num) {
// Sum only the odd numbers and return the value // Sum only the odd numbers and return the value
return arrFib.reduce((acc, curr) => { return arrFib.reduce((acc, curr) => {
return acc + curr * (curr % 2); return acc + curr * (curr % 2);
}); }, 0);
} }
// test here // test here
sumFibs(4); sumFibs(4);
``` ```
![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ":foguete:") [Executar código](https://repl.it/@kr3at0/SumAllOddFibonacciNumbers) ![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ":foguete:") [Executar código](https://repl.it/repls/ImpassionedFineConnection)
### Explicação do código: ### Explicação do código:

View File

@ -93,14 +93,14 @@ function sumFibs(num) {
// Sum only the odd numbers and return the value // Sum only the odd numbers and return the value
return arrFib.reduce((acc, curr) => { return arrFib.reduce((acc, curr) => {
return acc + curr * (curr % 2); return acc + curr * (curr % 2);
}); }, 0);
} }
// test here // test here
sumFibs(4); sumFibs(4);
``` ```
![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ": Ракета:") [Код запуска](https://repl.it/@kr3at0/SumAllOddFibonacciNumbers) ![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ": Ракета:") [Код запуска](https://repl.it/repls/ImpassionedFineConnection)
### Код Объяснение: ### Код Объяснение:

View File

@ -93,14 +93,14 @@ function sumFibs(num) {
// Sum only the odd numbers and return the value // Sum only the odd numbers and return the value
return arrFib.reduce((acc, curr) => { return arrFib.reduce((acc, curr) => {
return acc + curr * (curr % 2); return acc + curr * (curr % 2);
}); }, 0);
} }
// test here // test here
sumFibs(4); sumFibs(4);
``` ```
![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ":cohete:") [Ejecutar código](https://repl.it/@kr3at0/SumAllOddFibonacciNumbers) ![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ":cohete:") [Ejecutar código](https://repl.it/repls/ImpassionedFineConnection)
### Explicación del código: ### Explicación del código: