https://github.com/wtetsu/uniqlist
https://github.com/wtetsu/uniqlist
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/wtetsu/uniqlist
- Owner: wtetsu
- License: mit
- Created: 2018-12-12T01:58:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-03-18T12:24:33.000Z (about 6 years ago)
- Last Synced: 2024-08-10T23:44:23.968Z (almost 2 years ago)
- Language: JavaScript
- Size: 147 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UniqList
[](https://travis-ci.org/wtetsu/uniqlist)
[](https://codeclimate.com/github/wtetsu/uniqlist)
[](https://badge.fury.io/js/uniqlist)
## Install
```
npm install uniqlist
```
## How to use
### Example 1
```js
const UniqList = require("uniqlist");
const ul = new UniqList();
ul.push(10);
ul.push(10);
ul.push(11);
ul.push(11);
ul.push(11);
ul.size(); // 2
ul.get(0); // 10
ul.get(1); // 11
const arr = ul.toArray(); // [10, 11]
```
### Example 2
```js
const UniqList = require("uniqlist");
const ul = new UniqList();
ul.push({ msg: "hello!" }, "key10");
ul.push({ msg: "hello!!" }, "key10");
ul.push({ msg: "hello!!!" }, "key10");
ul.push({ msg: "hello?" }, "key11");
ul.push({ msg: "hello??" }, "key11");
ul.push({ msg: "hello???" }, "key11");
ul.size(); // 2
ul.get(0).msg; // "hello!"
ul.get(1).msg; // "hello?"
const arr = ul.toArray(); // [{ msg:"hello!"}, { msg:"hello?"}]
```
### Example 3
```js
const ul = new UniqList();
ul.filter = a => a % 2 == 0;
ul.push(1);
ul.push(3);
ul.push(5);
ul.size(); // 0
ul.push(1);
ul.push(2);
ul.push(3);
ul.push(4);
ul.size(); // 2
const arr = ul.toArray(); // [2, 4]
```