From 0f5c28cfdf82c96bd20e54e67f837339bd7bf71c Mon Sep 17 00:00:00 2001 From: Kiko Almela Date: Tue, 13 Nov 2018 08:24:50 +0100 Subject: [PATCH] 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. --- .../sum-all-odd-fibonacci-numbers/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-odd-fibonacci-numbers/index.md b/guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-odd-fibonacci-numbers/index.md index 1e57c13bd1..4463b97236 100644 --- a/guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-odd-fibonacci-numbers/index.md +++ b/guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-odd-fibonacci-numbers/index.md @@ -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); }); }