From b76e9ba0bc00b46896d19276e9ab0015b06e97db Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Fri, 22 Dec 2017 18:51:43 -0800 Subject: [PATCH 1/3] [UPDATE] Flatten updated to use ES6 spread --- snippets/flatten.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/flatten.md b/snippets/flatten.md index 69a492572..deca1d752 100644 --- a/snippets/flatten.md +++ b/snippets/flatten.md @@ -2,9 +2,9 @@ Flattens an array. -Use `Array.reduce()` to get all elements inside the array and `concat()` to flatten them. +Using a new array we concatinate it with the spread input array causing a shallow flatten ```js -const flatten = arr => arr.reduce((a, v) => a.concat(v), []); +const flatten = arr => [ ].concat( ...arr ); // flatten([1,[2],3,4]) -> [1,2,3,4] ``` From ebb58195d8245d872d74ff33aad65b3d077827fb Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Fri, 22 Dec 2017 18:54:23 -0800 Subject: [PATCH 2/3] Fix the description to be a bit more proper --- snippets/flatten.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/flatten.md b/snippets/flatten.md index deca1d752..4542d6b18 100644 --- a/snippets/flatten.md +++ b/snippets/flatten.md @@ -2,7 +2,7 @@ Flattens an array. -Using a new array we concatinate it with the spread input array causing a shallow flatten +Using a new array we concatinate it with the spread input array causing a shallow denesting of any contained arrays ```js const flatten = arr => [ ].concat( ...arr ); From 0108f8859daa37dc0cbdbb3a6b43a565d944a4e7 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 23 Dec 2017 12:00:38 +0200 Subject: [PATCH 3/3] Update flatten.md --- snippets/flatten.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/flatten.md b/snippets/flatten.md index 4542d6b18..f070f2cae 100644 --- a/snippets/flatten.md +++ b/snippets/flatten.md @@ -2,7 +2,7 @@ Flattens an array. -Using a new array we concatinate it with the spread input array causing a shallow denesting of any contained arrays +Use a new array and concatenate it with the spread input array causing a shallow denesting of any contained arrays. ```js const flatten = arr => [ ].concat( ...arr );