Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

array-uniq

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-uniq - npm Package Compare versions

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;
}

4

package.json
{
"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).

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc