source: trip-planner-front/node_modules/uniqs/README.md@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1[![Build Status](https://travis-ci.org/fgnass/uniqs.svg?branch=master)](https://travis-ci.org/fgnass/uniqs)
2
3### Tiny utility to create unions and de-duplicated lists.
4
5Example:
6
7```js
8var uniqs = require('uniqs');
9
10var foo = { foo: 23 };
11var list = [3, 2, 2, 1, foo, foo];
12
13uniqs(list);
14// => [3, 2, 1, { foo: 23 }]
15```
16
17You can pass multiple lists to create a union:
18
19```js
20uniqs([2, 1, 1], [2, 3, 3, 4], [4, 3, 2]);
21// => [2, 1, 3, 4]
22```
23
24Passing individual items works too:
25```js
26uniqs(3, 2, 2, [1, 1, 2]);
27// => [3, 2, 1]
28```
29
30### Summary
31
32* Uniqueness is defined based on strict object equality.
33* The lists do not need to be sorted.
34* The resulting array contains the items in the order of their first appearance.
35
36### About
37
38This package has been written to accompany utilities like
39[flatten](https://npmjs.org/package/flatten) as alternative to full-blown
40libraries like underscore or lodash.
41
42The implementation is optimized for simplicity rather than performance and
43looks like this:
44
45```js
46module.exports = function uniqs() {
47 var list = Array.prototype.concat.apply([], arguments);
48 return list.filter(function(item, i) {
49 return i == list.indexOf(item);
50 });
51};
52```
53
54### License
55MIT
Note: See TracBrowser for help on using the repository browser.