New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

3

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

3

Performs a multi-level three-way comparison on numbers/strings and returns 1, 0, or -1.

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
decreased by-32.23%
Maintainers
1
Weekly downloads
 
Created
Source

3

Performs a multi-level three-way comparison on numbers/strings and returns 1, 0, or -1.

Primarily useful in complex sort() callbacks.

Installation

npm install 3 --save

Usage

const compare3Way = require('3')

const people = [
  {name: 'John', age: 27},
  {name: 'Stephen', age: 26},
  {name: 'John', age: 25},
]

// Sort by name
people.sort((a, b) => compare3Way(a.name, b.name)) // John, John, Stephen

// Sort by age
people.sort((a, b) => compare3Way(a.age, b.age)) // John, Stephen, John

// Multi-level sort: First by name, then by age
people.sort((a, b) => compare3Way(a.name, b.name, a.age, b.age)) // John (#2), John (#1), Stephen

// Normally empty strings are sorted so they come first,
// but you can use the `emptyStringsLast` option to change that.
compare3Way('', 'str') // -1
compare3Way('', 'str', {emptyStringsLast: true}) // 1

Keywords

FAQs

Package last updated on 03 Feb 2018

Did you know?

Socket

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.

Install

Related posts

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