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:
		| @@ -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); | ||||
|         }); | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user