lhl 6ff0e96ad3 8-4-1 | преди 1 година | |
---|---|---|
.. | ||
.travis.yml | преди 1 година | |
README.md | преди 1 година | |
index.js | преди 1 година | |
package.json | преди 1 година | |
test.js | преди 1 година |
Example:
var uniqs = require('uniqs');
var foo = { foo: 23 };
var list = [3, 2, 2, 1, foo, foo];
uniqs(list);
// => [3, 2, 1, { foo: 23 }]
You can pass multiple lists to create a union:
uniqs([2, 1, 1], [2, 3, 3, 4], [4, 3, 2]);
// => [2, 1, 3, 4]
Passing individual items works too:
uniqs(3, 2, 2, [1, 1, 2]);
// => [3, 2, 1]
This package has been written to accompany utilities like flatten as alternative to full-blown libraries like underscore or lodash.
The implementation is optimized for simplicity rather than performance and looks like this:
module.exports = function uniqs() {
var list = Array.prototype.concat.apply([], arguments);
return list.filter(function(item, i) {
return i == list.indexOf(item);
});
};
MIT