Comparing version 0.1.0 to 0.1.1
28
index.js
'use strict'; | ||
function uniq(arr) { | ||
// we have 3 implementations for unique, written in increasing order of efficiency | ||
// 1 - no Set type is defined | ||
function uniqNoSet(arr) { | ||
var ret = []; | ||
@@ -15,3 +18,15 @@ | ||
// 2 - a simple Set type is defined | ||
function uniqSet(arr) { | ||
var seen = new Set(); | ||
return arr.filter(function (el) { | ||
if (!seen.has(el)) { | ||
seen.add(el); | ||
return true; | ||
} | ||
}); | ||
} | ||
// 3 - a standard Set type is defined and it has a forEach method | ||
function uniqSetWithForEach(arr) { | ||
var ret = []; | ||
@@ -26,2 +41,11 @@ | ||
module.exports = 'Set' in global ? uniqSet : uniq; | ||
// export the relevant implementation | ||
if ('Set' in global) { | ||
if (typeof Set.prototype.forEach === 'function') { | ||
module.exports = uniqSetWithForEach; | ||
} else { | ||
module.exports = uniqSet; | ||
} | ||
} else { | ||
module.exports = uniqNoSet; | ||
} |
{ | ||
"name": "array-uniq", | ||
"version": "0.1.0", | ||
"description": "Returns a new array without duplicates", | ||
"version": "0.1.1", | ||
"description": "Create an array without duplicates", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": "sindresorhus/array-uniq", |
# array-uniq [![Build Status](https://travis-ci.org/sindresorhus/array-uniq.svg?branch=master)](https://travis-ci.org/sindresorhus/array-uniq) | ||
> Returns a new array without duplicates | ||
> Create an array without duplicates | ||
@@ -5,0 +5,0 @@ It's already pretty fast, but will be much faster when [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) becomes available in V8 (especially with large arrays). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2176
40