sorted-array

An implementation of John von Neumann's sorted arrays in JavaScript. Implements insertion sort and binary search for fast insertion and deletion.

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
Last updated 6 years ago by aaditmshah .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install sorted-array 
SYNC missed versions from official npm registry.

Sorted Array

An implementation of John von Neumann's sorted arrays in JavaScript. Implements insertion sort and binary search for fast insertion and deletion.

Installation

Sorted arrays may be installed on node.js via the node package manager using the command npm install sorted-array.

You may also install it on RingoJS using the command ringo-admin install javascript/sorted-array.

You may install it as a component for web apps using the command component install javascript/sorted-array.

Usage

The six line tutorial on sorted arrays:

var SortedArray = require("sorted-array");
var sorted = new SortedArray([3, 1, 5, 2, 4]);
console.dir(sorted.array);                     // [1, 2, 3, 4, 5]
sorted.search(3);                              // 2
sorted.remove(3);                              // [1, 2, 4, 5]
sorted.insert(3);                              // [1, 2, 3, 4, 5]

You may pass an optional compare function as a second argument to the SortedArray constructor.

You may also use the SortedArray.comparing(property, array) factory function to create a new SortedArray which compares values by their property. For example, to compare arrays by length:

var SortedArray = require("sorted-array");
var sorted = SortedArray.comparing(length, [[3,3,3], [1], [5,5,5,5,5], [2,2], [4,4,4,4]]);
console.dir(sorted.array);              // [[1], [2,2], [3,3,3], [4,4,4,4], [5,5,5,5,5]]

function length(a) {
    return a.length;
}

Current Tags

  • 2.0.4                                ...           latest (6 years ago)

8 Versions

  • 2.0.4 [deprecated]           ...           6 years ago
  • 2.0.3 [deprecated]           ...           6 years ago
  • 2.0.2 [deprecated]           ...           7 years ago
  • 2.0.1 [deprecated]           ...           10 years ago
  • 2.0.0 [deprecated]           ...           10 years ago
  • 1.1.1 [deprecated]           ...           11 years ago
  • 1.1.0 [deprecated]           ...           12 years ago
  • 1.0.0 [deprecated]           ...           12 years ago
Maintainers (1)
Downloads
Total 8
Today 0
This Week 0
This Month 8
Last Day 0
Last Week 8
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE