arr-diff
Advanced tools
Comparing version 1.0.1 to 1.1.0
39
index.js
@@ -10,11 +10,6 @@ /*! | ||
var flatten = require('arr-flatten'); | ||
var slice = require('array-slice'); | ||
/** | ||
* Expose `diff` | ||
*/ | ||
module.exports = diff; | ||
/** | ||
* Return the difference between the first array and | ||
@@ -39,23 +34,27 @@ * additional arrays. | ||
function diff(a, b, c) { | ||
var len = a.length; | ||
var arr = []; | ||
var rest; | ||
function diff(arr, arrays) { | ||
var argsLen = arguments.length; | ||
var len = arr.length, i = -1; | ||
var res = [], arrays; | ||
if (!b) { | ||
return a; | ||
if (argsLen === 1) { | ||
return arr; | ||
} | ||
if (!c) { | ||
rest = b; | ||
} else { | ||
rest = [].concat.apply([], slice(arguments, 1)); | ||
if (argsLen > 2) { | ||
arrays = flatten(slice(arguments, 1)); | ||
} | ||
while (len--) { | ||
if (rest.indexOf(a[len]) === -1) { | ||
arr.unshift(a[len]); | ||
while (++i < len) { | ||
if (!~arrays.indexOf(arr[i])) { | ||
res.push(arr[i]); | ||
} | ||
} | ||
return arr; | ||
return res; | ||
} | ||
/** | ||
* Expose `diff` | ||
*/ | ||
module.exports = diff; |
{ | ||
"name": "arr-diff", | ||
"description": "Returns an array with only the unique values from the first array, by excluding all values from additional arrays using strict equality for comparisons.", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/jonschlinkert/arr-diff", | ||
@@ -10,13 +10,10 @@ "author": { | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/jonschlinkert/arr-diff.git" | ||
}, | ||
"repository": "jonschlinkert/arr-diff", | ||
"bugs": { | ||
"url": "https://github.com/jonschlinkert/arr-diff/issues" | ||
}, | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/arr-diff/blob/master/LICENSE-MIT" | ||
}, | ||
"license": "MIT", | ||
"files": [ | ||
"index.js" | ||
], | ||
"main": "index.js", | ||
@@ -27,13 +24,14 @@ "engines": { | ||
"scripts": { | ||
"test": "mocha -R spec" | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"array-slice": "^0.2.2" | ||
"arr-flatten": "^1.0.1", | ||
"array-slice": "^0.2.3" | ||
}, | ||
"devDependencies": { | ||
"array-differ": "^1.0.0", | ||
"benchmarked": "^0.1.3", | ||
"chalk": "^0.5.1", | ||
"mocha": "*", | ||
"should": "^4.0.4" | ||
"benchmarked": "^0.1.4", | ||
"chalk": "^1.1.1", | ||
"mocha": "^2.2.5", | ||
"should": "^7.0.4" | ||
}, | ||
@@ -46,3 +44,12 @@ "keywords": [ | ||
"difference" | ||
] | ||
], | ||
"verb": { | ||
"related": { | ||
"list": [ | ||
"arr-flatten", | ||
"array-filter", | ||
"array-intersection" | ||
] | ||
} | ||
} | ||
} |
@@ -1,30 +0,35 @@ | ||
# arr-diff [![NPM version](https://badge.fury.io/js/arr-diff.svg)](http://badge.fury.io/js/arr-diff) [![Build Status](https://travis-ci.org/jonschlinkert/arr-diff.svg)](https://travis-ci.org/jonschlinkert/arr-diff) | ||
# arr-diff [![NPM version](https://badge.fury.io/js/arr-diff.svg)](http://badge.fury.io/js/arr-diff) [![Build Status](https://travis-ci.org/jonschlinkert/arr-diff.svg)](https://travis-ci.org/jonschlinkert/arr-diff) | ||
> Returns an array with only the unique values from the first array, by excluding all values from additional arrays using strict equality for comparisons. | ||
Why another array `difference` lib? I wanted the [fastest, correct implementation](./benchmark) I could find. | ||
## Install | ||
## Install with [npm](npmjs.org) | ||
Install with [npm](https://www.npmjs.com/) | ||
```bash | ||
npm i arr-diff --save | ||
```sh | ||
$ npm i arr-diff --save | ||
``` | ||
### Install with [bower](https://github.com/bower/bower) | ||
```bash | ||
bower install arr-diff --save | ||
Install with [bower](http://bower.io/) | ||
```sh | ||
$ bower install arr-diff --save | ||
``` | ||
## Usage | ||
## API | ||
### [diff](index.js#L38) | ||
### [diff](index.js#L33) | ||
Return the difference between the first array and additional arrays. | ||
* `a` **{Array}** | ||
* `b` **{Array}** | ||
* `returns`: {Array} | ||
**Params** | ||
* `a` **{Array}** | ||
* `b` **{Array}** | ||
* `returns` **{Array}** | ||
**Example** | ||
```js | ||
var diff = require('{%= name %}'); | ||
var diff = require('arr-diff'); | ||
@@ -38,45 +43,34 @@ var a = ['a', 'b', 'c', 'd']; | ||
## Related projects | ||
* [arr-flatten](https://www.npmjs.com/package/arr-flatten): Recursively flatten an array or arrays. This is the fastest implementation of array flatten. | [homepage](https://github.com/jonschlinkert/arr-flatten) | ||
* [array-filter](https://www.npmjs.com/package/array-filter): Array#filter for older browsers. | [homepage](https://github.com/juliangruber/array-filter) | ||
* [array-intersection](https://www.npmjs.com/package/array-intersection): Return an array with the unique values present in _all_ given arrays using strict equality… [more](https://www.npmjs.com/package/array-intersection) | [homepage](https://github.com/jonschlinkert/array-intersection) | ||
## Run tests | ||
## Running tests | ||
```bash | ||
npm test | ||
Install dev dependencies: | ||
```sh | ||
$ npm i -d && npm test | ||
``` | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/arr-diff/issues/new). | ||
## Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
### Other javascript/node.js utils | ||
Copyright © 2015 Jon Schlinkert | ||
Released under the MIT license. | ||
Other projects that I maintain: | ||
- [arr-flatten](https://github.com/jonschlinkert/arr-flatten) | ||
- [arrayify-compact](https://github.com/jonschlinkert/arrayify-compact) | ||
- [compact-object](https://github.com/jonschlinkert/compact-object) | ||
- [delete](https://github.com/jonschlinkert/delete) | ||
- [for-in](https://github.com/jonschlinkert/for-in) | ||
- [for-own](https://github.com/jonschlinkert/for-own) | ||
- [has-any](https://github.com/jonschlinkert/has-any) | ||
- [has-value](https://github.com/jonschlinkert/has-value) | ||
- [is-number](https://github.com/jonschlinkert/is-number) | ||
- [is-plain-object](https://github.com/jonschlinkert/is-plain-object) | ||
- [mixin-deep](https://github.com/jonschlinkert/mixin-deep) | ||
- [mixin-object](https://github.com/jonschlinkert/mixin-object) | ||
- [object-length](https://github.com/jonschlinkert/object-length) | ||
- [omit-empty](https://github.com/jonschlinkert/omit-empty) | ||
- [reduce-object](https://github.com/jonschlinkert/reduce-object) | ||
## License | ||
Copyright (c) 2014 Jon Schlinkert | ||
Released under the MIT license | ||
*** | ||
_This file was generated by [verb](https://github.com/assemble/verb) on December 28, 2014._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on August 23, 2015._ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
5307
2
4
49
76
1
+ Addedarr-flatten@^1.0.1
+ Addedarr-flatten@1.1.0(transitive)
Updatedarray-slice@^0.2.3