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

complex-sort

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

complex-sort

0.0.1

  • 0.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

complex-sort

Simplify the creation of complex/compound sorts on JavaScript arrays

This module creates a sort function which is a compilation of the supplied sorting functions. In this way it accomplishes complex sorting with one or more sort criteria. It can also make complex sort logic more readable by breaking sort logic into discrete pieces.

Usage

var complexSort = require("complex-sort"),
    arrayToSort = [
        { p1: 1, p2: "b", id: "Peter"},
        { p1: 1, p2: "a", id: "Bjorn"}
    ];
    
arrayToSort.sort(complexSort({
    sortingFunctions: [ 
        function (a, b) { return a.p1 > b.p1 ? 1 : a.p1 < b.p1 ? -1 : 0; },
        function (a, b) { return a.p2 > b.p2 ? 1 : a.p2 < b.p2 ? -1 : 0; }
    ],
    invert: false//Just including this to document that you can reverse your sort
});

//arrayToSort now has Bjorn first (at 0) and Peter second

Question and comments are appreciated!

Keywords

FAQs

Package last updated on 03 Jun 2014

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