diff --git a/README.md b/README.md index cb8caefdf..a49415be7 100644 --- a/README.md +++ b/README.md @@ -1148,7 +1148,7 @@ differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Mat Returns a new array with `n` elements removed from the left. -Use `Array.prototype.slice()` to slice the remove the specified number of elements from the left. +Use `Array.prototype.slice()` to remove the specified number of elements from the left. ```js const drop = (arr, n = 1) => arr.slice(n); @@ -1171,7 +1171,7 @@ drop([1, 2, 3], 42); // [] Returns a new array with `n` elements removed from the right. -Use `Array.prototype.slice()` to slice the remove the specified number of elements from the right. +Use `Array.prototype.slice()` to remove the specified number of elements from the right. ```js const dropRight = (arr, n = 1) => arr.slice(0, -n); @@ -2327,9 +2327,9 @@ The `func` is invoked with three arguments (`value, index, array`). const remove = (arr, func) => Array.isArray(arr) ? arr.filter(func).reduce((acc, val) => { - arr.splice(arr.indexOf(val), 1); - return acc.concat(val); - }, []) + arr.splice(arr.indexOf(val), 1); + return acc.concat(val); + }, []) : []; ``` @@ -4731,6 +4731,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]); + const lengthIs4 = checkProp(l => l === 4, 'length'); lengthIs4([]); // false lengthIs4([1,2,3,4]); // true diff --git a/docs/function.html b/docs/function.html index d17cca87e..269dcbf67 100644 --- a/docs/function.html +++ b/docs/function.html @@ -151,6 +151,7 @@ console.log< + const lengthIs4 = checkProp(l => l === 4, 'length'); lengthIs4([]); // false lengthIs4([1,2,3,4]); // true diff --git a/docs/index.html b/docs/index.html index 272e522ef..29954214e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -146,11 +146,11 @@ differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x); // [2]

differenceWith

Filters out all values from an array for which the comparator function does not return true.

Use Array.prototype.filter() and Array.prototype.findIndex() to find the appropriate values.

const differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1);
 
differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b)); // [1, 1.2]
-

drop

Returns a new array with n elements removed from the left.

Use Array.prototype.slice() to slice the remove the specified number of elements from the left.

const drop = (arr, n = 1) => arr.slice(n);
+

drop

Returns a new array with n elements removed from the left.

Use Array.prototype.slice() to remove the specified number of elements from the left.

const drop = (arr, n = 1) => arr.slice(n);
 
drop([1, 2, 3]); // [2,3]
 drop([1, 2, 3], 2); // [3]
 drop([1, 2, 3], 42); // []
-

dropRight

Returns a new array with n elements removed from the right.

Use Array.prototype.slice() to slice the remove the specified number of elements from the right.

const dropRight = (arr, n = 1) => arr.slice(0, -n);
+

dropRight

Returns a new array with n elements removed from the right.

Use Array.prototype.slice() to remove the specified number of elements from the right.

const dropRight = (arr, n = 1) => arr.slice(0, -n);
 
dropRight([1, 2, 3]); // [1,2]
 dropRight([1, 2, 3], 2); // [1]
 dropRight([1, 2, 3], 42); // []
@@ -413,9 +413,9 @@
 

remove

Removes elements from an array for which the given function returns false.

Use Array.prototype.filter() to find array elements that return truthy values and Array.prototype.reduce() to remove elements using Array.prototype.splice(). The func is invoked with three arguments (value, index, array).

const remove = (arr, func) =>
   Array.isArray(arr)
     ? arr.filter(func).reduce((acc, val) => {
-        arr.splice(arr.indexOf(val), 1);
-        return acc.concat(val);
-      }, [])
+      arr.splice(arr.indexOf(val), 1);
+      return acc.concat(val);
+    }, [])
     : [];
 
remove([1, 2, 3, 4], n => n % 2 === 0); // [2, 4]
 

sample

Returns a random element from an array.

Use Math.random() to generate a random number, multiply it by length and round it off to the nearest whole number using Math.floor(). This method also works with strings.

const sample = arr => arr[Math.floor(Math.random() * arr.length)];
diff --git a/snippets/checkProp.md b/snippets/checkProp.md
index ef740e3e8..1c13eda1d 100644
--- a/snippets/checkProp.md
+++ b/snippets/checkProp.md
@@ -16,6 +16,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
 
 
 
+
 const lengthIs4 = checkProp(l => l === 4, 'length');
 lengthIs4([]); // false
 lengthIs4([1,2,3,4]); // true
diff --git a/snippets/remove.md b/snippets/remove.md
index a8c472774..58de9c2e0 100644
--- a/snippets/remove.md
+++ b/snippets/remove.md
@@ -9,9 +9,9 @@ The `func` is invoked with three arguments (`value, index, array`).
 const remove = (arr, func) =>
   Array.isArray(arr)
     ? arr.filter(func).reduce((acc, val) => {
-        arr.splice(arr.indexOf(val), 1);
-        return acc.concat(val);
-      }, [])
+      arr.splice(arr.indexOf(val), 1);
+      return acc.concat(val);
+    }, [])
     : [];
 ```
 
diff --git a/test/_30s.js b/test/_30s.js
index c9873d4dc..194dd4829 100644
--- a/test/_30s.js
+++ b/test/_30s.js
@@ -1001,9 +1001,9 @@ const reject = (pred, array) => array.filter((...args) => !pred(...args));
 const remove = (arr, func) =>
   Array.isArray(arr)
     ? arr.filter(func).reduce((acc, val) => {
-        arr.splice(arr.indexOf(val), 1);
-        return acc.concat(val);
-      }, [])
+      arr.splice(arr.indexOf(val), 1);
+      return acc.concat(val);
+    }, [])
     : [];
 const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, '');
 const renameKeys = (keysMap, obj) =>