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

array-order

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-order

sort an array in-place to a preset order

  • 0.9.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

array-order

in-place sorting of arrays

ExampleFeaturesLimitationsWhyAPILicense

summary

  • sort creates a sorter to sort multiple columns (ref:Array [,compare]) => (a:Array) => a
  • rank performs reordering based on given ranks (ranks:Array, a:Array) => a:Array
  • heap creates a function that performs permutation, each one different a:Array => () => a

example

import sort from 'array-order/sort.js'

const columns = [[2,1,0,3], ['c','b','a','d']]
columns.forEach(sort(columns[0]))
//each column now sorted according to the first one
//columns == [ [0,1,2,3], ['a','b','c','d'] ]

exports

  • named: import {sort} from 'array-order'
  • default: import rank from 'array-order/rank.js'

sort order

the sort factory can take an additional compare function to change the sort order: (ref:Array [,compare]) => (a:Array) => a

  • undefined increasing numeric order
  • any negative number decreasing numeric order
  • a normal compare function just like Array.prototype.sort: (a, b) => a - b

other utilities

the following other in-place utilities are needed internally and are also available

  • array-order/swap.js in place swap of 2 items (a:Array, i:number, j:number) => a
  • array-order/shift.js in place left-swap from i to j (a:Array, i:number, j:number) => a

License

MIT © Hugo Villeneuve

Keywords

FAQs

Package last updated on 26 Apr 2020

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