From 734b9ad08709d70dd9ba070dfc4e23ab58621fb3 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Wed, 17 Jan 2018 17:41:21 +0000 Subject: [PATCH] Travis build: 1282 --- README.md | 46 +++++++++++++++++++++++----------------------- docs/index.html | 6 +++--- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 90f5ba61f..f2638c72f 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,6 @@ average(1, 2, 3); * [`deepFlatten`](#deepflatten) * [`difference`](#difference) * [`differenceWith`](#differencewith) -* [`distinctValuesOfArray`](#distinctvaluesofarray) * [`dropElements`](#dropelements) * [`dropRight`](#dropright) * [`everyNth`](#everynth) @@ -140,6 +139,7 @@ average(1, 2, 3); * [`take`](#take) * [`takeRight`](#takeright) * [`union`](#union) +* [`uniqueElements`](#uniqueelements) * [`without`](#without) * [`zip`](#zip) * [`zipObject`](#zipobject) @@ -710,28 +710,6 @@ differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Mat
[⬆ Back to top](#table-of-contents) -### distinctValuesOfArray - -Returns all the distinct values of an array. - -Use ES6 `Set` and the `...rest` operator to discard all duplicated values. - -```js -const distinctValuesOfArray = arr => [...new Set(arr)]; -``` - -
-Examples - -```js -distinctValuesOfArray([1, 2, 2, 3, 4, 4, 5]); // [1,2,3,4,5] -``` - -
- -
[⬆ Back to top](#table-of-contents) - - ### dropElements Removes elements in an array until the passed function returns `true`. Returns the remaining elements in the array. @@ -1815,6 +1793,28 @@ union([1, 2, 3], [4, 3, 2]); // [1,2,3,4]
[⬆ Back to top](#table-of-contents) +### uniqueElements + +Returns all unique values of an array. + +Use ES6 `Set` and the `...rest` operator to discard all duplicated values. + +```js +const uniqueElements = arr => [...new Set(arr)]; +``` + +
+Examples + +```js +uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1,2,3,4,5] +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### without Filters out the elements of an array, that have one of the specified values. diff --git a/docs/index.html b/docs/index.html index 5a4358afd..9b11b1347 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 ]
@@ -111,8 +111,6 @@ Object.assig
 
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.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) => {
   while (arr.length > 0 && !func(arr[0])) arr = arr.slice(1);
   return arr;
@@ -342,6 +340,8 @@ Object.assig
 takeRight([1, 2, 3]); // [3]
 

union

Returns every element that exists in any of the two arrays once.

Create a Set with all values of a and b and convert to an array.

const union = (a, b) => Array.from(new Set([...a, ...b]));
 
union([1, 2, 3], [4, 3, 2]); // [1,2,3,4]
+

uniqueElements

Returns all unique values of an array.

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

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

without

Filters out the elements of an array, that have one of the specified values.

Use Array.filter() to create an array excluding(using !Array.includes()) all given values.

(For a snippet that mutates the original array see pull)

const without = (arr, ...args) => arr.filter(v => !args.includes(v));
 
without([2, 1, 2, 3], 1, 2); // [3]
 

zip

Creates an array of elements, grouped based on the position in the original arrays.

Use Math.max.apply() to get the longest array in the arguments. Creates an array with that length as return value and use Array.from() with a map-function to create an array of grouped elements. If lengths of the argument-arrays vary, undefined is used where no value could be found.

const zip = (...arrays) => {