arr-diff
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "arr-diff", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": [ | ||
@@ -5,0 +5,0 @@ "index.js" |
17
index.js
@@ -27,16 +27,21 @@ /*! | ||
module.exports = function difference(a, b) { | ||
var alen = a.length - 1; | ||
var blen = b.length; | ||
if (alen === 0) { | ||
if (a == null) { | ||
return []; | ||
} | ||
if (blen === 0) { | ||
if (!Array.isArray(b)) { | ||
return a; | ||
} | ||
if (!Array.isArray(a)) { | ||
throw new TypeError(); | ||
} | ||
var alen = a.length; | ||
var blen = b.length; | ||
var arr = []; | ||
for (var i = alen; i >= 0; i--) { | ||
for (var i = 0; i < alen; i++) { | ||
var key = a[i]; | ||
if (b.indexOf(key) === -1) { | ||
@@ -43,0 +48,0 @@ arr.push(key); |
{ | ||
"name": "arr-diff", | ||
"description": "Return an array with only the unique values present in all given arrays using strict equality for comparisons.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/jonschlinkert/arr-diff", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -73,2 +73,2 @@ # arr-diff [![NPM version](https://badge.fury.io/js/arr-diff.svg)](http://badge.fury.io/js/arr-diff) | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 26, 2014._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 02, 2014._ |
10
test.js
@@ -16,4 +16,10 @@ /*! | ||
diff(['a', 'b', 'c'], ['b', 'c', 'e']).should.eql(['a']); | ||
diff(['foo', 'b', 'c', 'e', 'bar'], ['b', 'foo', 'e']).should.eql(['bar', 'c']); | ||
diff(['foo', 'b', 'c', 'e', 'bar'], ['b', 'foo', 'e']).should.eql(['c', 'bar']); | ||
diff(['foo', 'foo'], ['a', 'b', 'c']).should.eql(['foo', 'foo']); | ||
diff(['foo'], ['a', 'b', 'c']).should.eql(['foo']); | ||
}); | ||
}); | ||
it('should return an empty array if no unique elements are in the first array:', function () { | ||
diff(['foo'], ['a', 'b', 'c', 'foo']).should.eql([]); | ||
}); | ||
}); |
8563
69