youneek

2.0.1 • Public • Published

youneek

A function to filter unique (you-neek) values

Why?

You can read about it on Medium

How to use it?

npm install youneek

const unique = require('youneek');
 
const arr = [1,2,3,4,1,3,5,8,9,9];
 
/* Make sure you call unique! See why below */
const result = arr.filter(unique());
 
// result === [1, 2, 3, 4, 5, 8, 9];

Copy Paste

Though to be honest, you could copy and paste this. It's really small and I won't begrudge you for doing that, but maybe give me a star?

const unique = () => {
    let cache;  
    return (elem, index, array) => {
        if (!cache) cache = new Set(array);
        return cache.delete(elem);
    };
};

Try it out

Try it out with runkit

Older browsers

This package uses new Set. If you are on an older browser you may need a polyfill.

Readme

Keywords

Package Sidebar

Install

npm i youneek

Weekly Downloads

4

Version

2.0.1

License

MIT

Unpacked Size

3.03 kB

Total Files

4

Last publish

Collaborators

  • s-taylor