From 1b516a8e748311d6cc8bc1e7002ac9916a8f65eb Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 9 Mar 2018 19:38:38 +0200 Subject: [PATCH] Resolve #622 --- snippets/flatten.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/snippets/flatten.md b/snippets/flatten.md index d39dd9467..854d27a53 100644 --- a/snippets/flatten.md +++ b/snippets/flatten.md @@ -9,9 +9,11 @@ Omit the second argument, `depth` to flatten only to a depth of `1` (single flat ```js const flatten = (arr, depth = 1) => - depth !== 1 - ? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flatten(v, depth - 1) : v), []) - : arr.reduce((a, v) => a.concat(v), []); + arr.reduce( + (a, v) => + a.concat(depth > 1 && Array.isArray(v) ? flatten(v, depth - 1) : v), + [], + ); ``` ```js