diff --git a/README.md b/README.md index 33a6f12a1..87098f99b 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,6 @@ average(1, 2, 3); * [`everyNth`](#everynth) * [`filterNonUnique`](#filternonunique) * [`flatten`](#flatten) -* [`flattenDepth`](#flattendepth) * [`forEachRight`](#foreachright) * [`groupBy`](#groupby) * [`head`](#head) @@ -799,34 +798,6 @@ flatten([1, [2, [3, [4, 5], 6], 7], 8], 2); // [1, 2, 3, [4, 5], 6, 7, 8]
[⬆ Back to top](#table-of-contents) -### flattenDepth - -Flattens an array up to the specified depth. - -Use recursion, decrementing `depth` by 1 for each level of depth. -Use `Array.reduce()` and `Array.concat()` to merge elements or arrays. -Base case, for `depth` equal to `1` stops recursion. -Omit the second element, `depth` to flatten only to a depth of `1` (single flatten). - -```js -const flattenDepth = (arr, depth = 1) => - depth != 1 - ? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flattenDepth(v, depth - 1) : v), []) - : arr.reduce((a, v) => a.concat(v), []); -``` - -
-Examples - -```js -flattenDepth([1, [2], 3, 4]); // [1,2,3,4] -``` - -
- -
[⬆ Back to top](#table-of-contents) - - ### forEachRight Executes a provided function once for each array element, starting from the array's last element. @@ -5300,6 +5271,7 @@ const httpPost = (url, callback, data = null, err = console.error) => { + const newPost = { "userId": 1, "id": 1337, diff --git a/docs/index.html b/docs/index.html index d4b15929b..6f80a9058 100644 --- a/docs/index.html +++ b/docs/index.html @@ -50,7 +50,7 @@ scrollToTop(); } }, false); - }

logo 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
+      }

logo 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
 
Promise.resolve([1, 2, 3])
   .then(call('map', x => 2 * x))
   .then(console.log); //[ 2, 4, 6 ]
@@ -125,11 +125,6 @@ Object.assig
     : arr.reduce((a, v) => a.concat(v), []);
 
flatten([1, [2], 3, 4]); // [1, 2, 3, 4]
 flatten([1, [2, [3, [4, 5], 6], 7], 8], 2); // [1, 2, 3, [4, 5], 6, 7, 8]
-

flattenDepth

Flattens an array up to the specified depth.

Use recursion, decrementing depth by 1 for each level of depth. Use Array.reduce() and Array.concat() to merge elements or arrays. Base case, for depth equal to 1 stops recursion. Omit the second element, depth to flatten only to a depth of 1 (single flatten).

const flattenDepth = (arr, depth = 1) =>
-  depth != 1
-    ? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flattenDepth(v, depth - 1) : v), [])
-    : arr.reduce((a, v) => a.concat(v), []);
-
flattenDepth([1, [2], 3, 4]); // [1,2,3,4]
 

forEachRight

Executes a provided function once for each array element, starting from the array's last element.

Use Array.slice(0) to clone the given array, Array.reverse() to reverse it and Array.forEach() to iterate over the reversed array.

const forEachRight = (arr, callback) =>
   arr
     .slice(0)
@@ -1175,6 +1170,7 @@ Logs: {
 
 
 
+
 const newPost = {
   "userId": 1,
   "id": 1337,
diff --git a/snippets/httpPost.md b/snippets/httpPost.md
index 7432560a7..55d29a095 100644
--- a/snippets/httpPost.md
+++ b/snippets/httpPost.md
@@ -29,6 +29,7 @@ const httpPost = (url, callback, data = null, err = console.error) => {
 
 
 
+
 const newPost = {
   "userId": 1,
   "id": 1337,
diff --git a/tag_database b/tag_database
index ce9bf0ad2..bfbd0adbb 100644
--- a/tag_database
+++ b/tag_database
@@ -44,7 +44,6 @@ factorial:math,recursion
 fibonacci:math,array
 filterNonUnique:array
 flatten:array
-flattenDepth:array,recursion
 flip:adapter,function
 forEachRight:array,function
 formatDuration:date,math,string,utility