jonschlinkert / arr-diff Goto Github PK
View Code? Open in Web Editor NEWReturns an array with only the unique values from all given arrays using strict equality for comparisons.
Home Page: https://github.com/jonschlinkert
License: MIT License
Returns an array with only the unique values from all given arrays using strict equality for comparisons.
Home Page: https://github.com/jonschlinkert
License: MIT License
var diff = require('arr-diff');
var a= ["a", "b", "c", "d", [1, 2]];
var b= [ "b", "c", "d", "e", [1, 2], [3]];
console.log(diff(a, b))
expected => ['a', 'd', [3]]
actual => ['a', [1, 2]]
The first, only find different a and b, not different b and a,
The second, if It has object, can not compare γCan you understand me?
edited by @doowb: code formating
Ignore -- found the issue :(
I was thinking maybe it could be possible to use Set
instead to do the same thing...
A benchmark for it maybe?
var a = ['a', 'b', 'c', 'd'];
var b = ['b', 'c'];
var set = new Set(a)
b.forEach(a => set.delete(a))
Array.from(set) // => ['a', 'd']
Also in many situations it's wasteful to cast the set into an array... ppl only do it to keep the same signature and never used set in the first place
curious to see a benchmark for this native solution
There are many things I would like to change:
arr-diff/benchmark/code/filter.js
Line 3 in ea84b7d
function
instead of arrow functionarr-diff/benchmark/code/filter.js
Line 3 in ea84b7d
arrays
for a parameter, but is actually used like const arrays =
. Uses arguments
, when it could use ...arrays
.arr-diff/benchmark/code/filter.js
Line 4 in ea84b7d
[].concat()
instead of [].concat.apply()
. Uses [].slice
when Array.prototype.slice
makes more sense.arr-diff/benchmark/code/filter.js
Line 6 in ea84b7d
includes
instead of indexOf
Can I make a pull request changing this? Should I add a new benchmark or edit the existing one?
With v3:
const diff = require('arr-diff')
const input = ['foo', 'bar']
console.error(diff(input, ['foo'])) // ['bar']
console.error(input) // ['bar']?!
It looks like diff()
modifies and returns the input
array. I'd expect it to return a new array and not touch the original input
.
Please tag version 3.0.0 of this module
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.