Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Package description
The uniq npm package is primarily used for removing duplicate elements from an array. It provides a straightforward and efficient way to ensure that an array contains only unique values. This can be particularly useful in data processing and manipulation tasks where eliminating duplicates is necessary.
Removing duplicates from an array
This feature allows you to pass an array to the uniq function, and it returns a new array with all the duplicate values removed. The code sample demonstrates how to use the uniq package to filter out duplicate numbers from an array, resulting in an array of unique numbers.
[...new Set([1, 2, 2, 3, 4, 4, 5])] // Returns [1, 2, 3, 4, 5]
lodash.uniq is a method from the popular Lodash library that provides similar functionality to uniq. It removes duplicate values from an array. Compared to uniq, lodash.uniq is part of a larger utility library, which might be preferable for projects already using Lodash for other purposes.
Underscore is another utility library that offers a wide range of functions for working with arrays, objects, and functions. Its _.uniq or _.unique function can be used to achieve the same result as the uniq package. The main difference is that Underscore provides a broader set of utilities, making it a heavier dependency if you only need unique array functionality.
Readme
Removes all duplicates from an array in place.
First install using npm:
npm install uniq
Then use it as follows:
var arr = [1, 1, 2, 2, 3, 5]
arr.sort()
require("uniq")(arr)
console.log(arr)
//Prints:
//
// 1,2,3,5
//
require("uniq")(array[, compare])
Removes all duplicates from a sorted array in place.
array
is the array to remove items fromcompare
is an optional comparison function that returns 0 when two items are equal, and something non-zero when they are different. If unspecified, then the default equals will be used.Returns: A reference to array
Time Complexity: O(array.length)
A few reasons:
(c) 2013 Mikola Lysenko. MIT License
FAQs
Removes duplicates from a sorted array in place
The npm package uniq receives a total of 3,919,775 weekly downloads. As such, uniq popularity was classified as popular.
We found that uniq demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.