diff --git a/README.md b/README.md index 6dff38d61..f5ccbea25 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ Use `reduce()` to get all elements that are not arrays, flatten each element tha ```js const deepFlatten = arr => - arr.reduce((a, v) => a.concat(Array.isArray(v) ? deepFlatten(v) : v), []); + arr.reduce( (a, v) => a.concat( Array.isArray(v) ? deepFlatten(v) : v ), []); // deepFlatten([1,[2],[[3],4],5]) -> [1,2,3,4,5] ``` @@ -240,7 +240,7 @@ Use `reduce()` to get all elements inside the array and `concat()` to flatten th ```js const flatten = arr => arr.reduce( (a, v) => a.concat(v), []); -// flatten([1,[2],3,4) -> [1,2,3,4] +// flatten([1,[2],3,4]) -> [1,2,3,4] ``` ### Get max value from array diff --git a/snippets/deep-flatten-array.md b/snippets/deep-flatten-array.md index 545c4c8d4..472143583 100644 --- a/snippets/deep-flatten-array.md +++ b/snippets/deep-flatten-array.md @@ -5,6 +5,6 @@ Use `reduce()` to get all elements that are not arrays, flatten each element tha ```js const deepFlatten = arr => - arr.reduce( (a, v) => a.concat( Array.isArray(v) ? flatten(v) : v ), []); + arr.reduce( (a, v) => a.concat( Array.isArray(v) ? deepFlatten(v) : v ), []); // deepFlatten([1,[2],[[3],4],5]) -> [1,2,3,4,5] ```