sindresorhus / array-uniq Goto Github PK
View Code? Open in Web Editor NEWCreate an array without duplicates
License: MIT License
Create an array without duplicates
License: MIT License
forEach
in safari's Set
is broken:
var set = new Set([1,2,3])
//undefined
set.forEach(function(el){console.log(el)})
//[1,2,3]
//not 1, 2, 3 as expected.
It doesn't know about creating set from array/iterable. (Safari 7.1).
So the whole array is passed as the first argument to forEach callback.
Possibly could check more precisely:
function doesForEachActuallyWork() {
var ret = false;
(new Set([true])).forEach(function (el) {
ret = el;
});
return ret === true;
}
"It's already pretty fast, but will be much faster when Set becomes available in V8 (especially with large arrays)."
Given that you are already depending on Node 6, probably this is kinda obsolete?
Separating 3 implementations in their own modules would make smaller builds when using Browserify and trying to support older browsers which don’t have Set.
For example:
var uniq = require('arr-uniq/no-set');
And in index.js
you would export required module.
Is this something you are willing to implement (or accept as PR)?
Please check out this issue: nodejs/node-v0.x-archive#8449
In short, the module breaks with the most recent node.
Sets are broken, please don't use them just yet.
@sindresorhus I noticed follow error while using gulp-filter with basic example.
I am using node v0.10.29. I am also using traceur in node env, which may also provider some shim for Set
. Wonder if anybody else seen this error?
undefined:1811
for (var $__25 = iterable[Symbol.iterator](),
^
TypeError: Property 'Symbol()' of object is not a function
at new Set (<anonymous>:1811:49)
at uniqSetWithForEach (/Developer/Work/spa-starter-kit/node_modules/gulp-filter/node_modules/multimatch/node_modules/array-union/node_modules/array-uniq/index.js:33:3)
at module.exports (/Developer/Work/spa-starter-kit/node_modules/gulp-filter/node_modules/multimatch/node_modules/array-union/index.js:5:9)
at /Developer/Work/spa-starter-kit/node_modules/gulp-filter/node_modules/multimatch/index.js:25:10
at Array.reduce (native)
at module.exports (/Developer/Work/spa-starter-kit/node_modules/gulp-filter/node_modules/multimatch/index.js:20:18)
at Transform._transform (/Developer/Work/spa-starter-kit/node_modules/gulp-filter/index.js:18:6)
at Transform._read (/Developer/Work/spa-starter-kit/node_modules/gulp-filter/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at Transform._write (/Developer/Work/spa-starter-kit/node_modules/gulp-filter/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
at doWrite (/Developer/Work/spa-starter-kit/node_modules/gulp-filter/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:238:10)
at writeOrBuffer (/Developer/Work/spa-starter-kit/node_modules/gulp-filter/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:228:5)
at Transform.Writable.write (/Developer/Work/spa-starter-kit/node_modules/gulp-filter/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:195:11)
at write (/Developer/Work/spa-starter-kit/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:605:24)
at flow (/Developer/Work/spa-starter-kit/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:614:7)
at Transform.pipeOnReadable (/Developer/Work/spa-starter-kit/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:646:5)
at Transform.emit (events.js:92:17)
I'm going to use your module in application node+typescript.
What about *.d.ts file for 'array-uniq'?
Is it possible to add typings?
Give a function to determine whether the two is same, especially for object in array
uniq([{a: 1}, {a: 1}], function(a, b) {
return a.a === b.a;
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.