From 2dd334cff5aa0f30d37b6b7e649663fa756d2031 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Thu, 4 Jan 2018 09:30:28 +0000 Subject: [PATCH] Travis build: 1012 --- README.md | 6 +++--- docs/index.html | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 212ddbe61..c87f97915 100644 --- a/README.md +++ b/README.md @@ -639,17 +639,17 @@ difference([1, 2, 3], [1, 2, 4]); // [3] Filters out all values from an array for which the comparator function does not return `true`. -Use `Array.filter()` and `Array.find()` to find the appropriate values. +Use `Array.filter()` and `Array.findIndex()` to find the appropriate values. ```js -const differenceWith = (arr, val, comp) => arr.filter(a => !val.find(b => comp(a, b))); +const differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1); ```
Examples ```js -differenceWith([1, 1.2, 1.5, 3], [1.9, 3], (a, b) => Math.round(a) == Math.round(b)); // [1, 1.2] +differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b)); // [1, 1.2] ```
diff --git a/docs/index.html b/docs/index.html index 0098a8ded..51f1657e4 100644 --- a/docs/index.html +++ b/docs/index.html @@ -86,8 +86,8 @@ Object.assig return a.filter(x => !s.has(x)); };
difference([1, 2, 3], [1, 2, 4]); // [3]
-

differenceWith

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

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

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

differenceWith

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

Use Array.filter() and Array.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]
 

distinctValuesOfArray

Returns all the distinct values of an array.

Use ES6 Set and the ...rest operator to discard all duplicated values.

const distinctValuesOfArray = arr => [...new Set(arr)];
 
distinctValuesOfArray([1, 2, 2, 3, 4, 4, 5]); // [1,2,3,4,5]
 

dropElements

Removes elements in an array until the passed function returns true. Returns the remaining elements in the array.

Loop through the array, using Array.slice() to drop the first element of the array until the returned value from the function is true. Returns the remaining elements.

const dropElements = (arr, func) => {