Merge pull request #554 from Chalarangelo/uniqueElements
FIX: Unique elements
This commit is contained in:
@ -1,13 +0,0 @@
|
||||
### 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)];
|
||||
```
|
||||
|
||||
```js
|
||||
distinctValuesOfArray([1, 2, 2, 3, 4, 4, 5]); // [1,2,3,4,5]
|
||||
```
|
||||
13
snippets/uniqueElements.md
Normal file
13
snippets/uniqueElements.md
Normal file
@ -0,0 +1,13 @@
|
||||
### 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)];
|
||||
```
|
||||
|
||||
```js
|
||||
uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1,2,3,4,5]
|
||||
```
|
||||
@ -33,7 +33,6 @@ difference:array,math
|
||||
differenceWith:array,function
|
||||
digitize:math,array
|
||||
distance:math
|
||||
distinctValuesOfArray:array
|
||||
dropElements:array,function
|
||||
dropRight:array
|
||||
elementIsVisibleInViewport:browser
|
||||
@ -203,6 +202,7 @@ truncateString:string
|
||||
truthCheckCollection:object,logic,array
|
||||
unescapeHTML:string,browser
|
||||
union:array,math
|
||||
uniqueElements:array
|
||||
untildify:node,string
|
||||
URLJoin:string,utility,regexp
|
||||
UUIDGeneratorBrowser:browser,utility,random
|
||||
|
||||
@ -1 +0,0 @@
|
||||
module.exports = distinctValuesOfArray = arr => [...new Set(arr)];
|
||||
@ -1,14 +0,0 @@
|
||||
const test = require('tape');
|
||||
const distinctValuesOfArray = require('./distinctValuesOfArray.js');
|
||||
|
||||
test('Testing distinctValuesOfArray', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof distinctValuesOfArray === 'function', 'distinctValuesOfArray is a Function');
|
||||
t.deepEqual(distinctValuesOfArray([1, 2, 2, 3, 4, 4, 5]), [1,2,3,4,5], "Returns all the distinct values of an array");
|
||||
//t.deepEqual(distinctValuesOfArray(args..), 'Expected');
|
||||
//t.equal(distinctValuesOfArray(args..), 'Expected');
|
||||
//t.false(distinctValuesOfArray(args..), 'Expected');
|
||||
//t.throws(distinctValuesOfArray(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
1
test/uniqueElements/uniqueElements.js
Normal file
1
test/uniqueElements/uniqueElements.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = uniqueElements = arr => [...new Set(arr)];
|
||||
14
test/uniqueElements/uniqueElements.test.js
Normal file
14
test/uniqueElements/uniqueElements.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
const test = require('tape');
|
||||
const uniqueElements = require('./uniqueElements.js');
|
||||
|
||||
test('Testing uniqueElements', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof uniqueElements === 'function', 'uniqueElements is a Function');
|
||||
t.deepEqual(uniqueElements([1, 2, 2, 3, 4, 4, 5]), [1,2,3,4,5], "Returns all unique values of an array");
|
||||
//t.deepEqual(uniqueElements(args..), 'Expected');
|
||||
//t.equal(uniqueElements(args..), 'Expected');
|
||||
//t.false(uniqueElements(args..), 'Expected');
|
||||
//t.throws(uniqueElements(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user