fix: update intermediate solution (#34263)

Intermediate code solution doesn't pass tests when the greater number is even because it's the starting acc without passing the reducer function that avoids even number.
Proposed solution: reverse the array before reduce.
This commit is contained in:
Kiko Almela
2018-11-13 08:24:50 +01:00
committed by Aman Mittal
parent f0ce844ca0
commit 0f5c28cfdf

View File

@ -89,7 +89,8 @@ As you get the next odd one, don't forget to add it to a global variable that ca
}
// Sum only the odd numbers and return the value
return arrFib.reduce((acc, curr) => {
// First, reverse the array to avoid starting acc with the first/greater number when it's even
return arrFib.reverse().reduce((acc, curr) => {
return acc + curr * (curr % 2);
});
}