diff --git a/README.md b/README.md index 336dcbddb..25490e54e 100644 --- a/README.md +++ b/README.md @@ -1278,7 +1278,7 @@ Use `Array.reduce()` to add values into the array, using the sum of the last two ```js const fibonacci = n => - Array.from({ length: n}).map(v => 0).reduce((acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i), []); + Array.from({ length: n}).reduce((acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i), []); // fibonacci(5) -> [0,1,1,2,3] ``` diff --git a/docs/index.html b/docs/index.html index b3aaf2cd5..2751272fd 100644 --- a/docs/index.html +++ b/docs/index.html @@ -810,7 +810,7 @@ Throws an exception if n is a negative number.

Create an empty array of the specific length, initializing the first two values (0 and 1). Use Array.reduce() to add values into the array, using the sum of the last two values, except for the first two.

const fibonacci = n =>
-  Array.from({ length: n}).map(v => 0).reduce((acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i), []);
+  Array.from({ length: n}).reduce((acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i), []);
 // fibonacci(5) -> [0,1,1,2,3]
 

gcd