phosphor-arrays
A collection of array utility functions.
Package Install
Prerequisites
npm install --save phosphor-arrays
Source Build
Prerequisites
git clone https://github.com/phosphorjs/phosphor-arrays.gitcd phosphor-arraysnpm install
Rebuild
npm run cleannpm run build
Run Tests
Follow the source build instructions first.
npm test
Build Docs
Follow the source build instructions first.
npm run docs
Navigate to docs/index.html
.
Supported Runtimes
The runtime versions which are currently known to work are listed below. Earlier versions may also work, but come with no guarantees.
- Node 0.12.7+
- IE 11+
- Firefox 32+
- Chrome 38+
Bundle for the Browser
Follow the package install instructions first.
npm install --save-dev browserifybrowserify myapp.js -o mybundle.js
Usage Examples
Note: This module is fully compatible with Node/Babel/ES6/ES5. Simply omit the type declarations when using a language other than TypeScript.
from 'phosphor-arrays'; // for-each with optional start index and wrap around;arrays.forEachdata, logger; // logs 1, 2, 3, 4arrays.forEachdata, logger, 2; // logs 3, 4arrays.forEachdata, logger, 2, true; // logs 3, 4, 1, 2arrays.forEachdata,; // reverse for-each with optional start index and wrap around;arrays.rforEachdata, logger; // logs 4, 3, 2, 1arrays.rforEachdata, logger, 2; // logs 3, 2, 1arrays.rforEachdata, logger, 2, true; // logs 3, 2, 1, 4arrays.rforEachdata,; // find-index with optional start index and wrap around;arrays.findIndexdata, isEven; // 1arrays.findIndexdata, isEven, 4; // 5arrays.findIndexdata, isEven, 6; // -1arrays.findIndexdata, isEven, 6, true; // 1 // reverse find-index with optional start index and wrap around;arrays.rfindIndexdata, isEven; // 5arrays.rfindIndexdata, isEven, 4; // 3arrays.rfindIndexdata, isEven, 0; // -1arrays.rfindIndexdata, isEven, 0, true; // 5 // find-value with optional start index and wrap around;arrays.finddata, isEven; // 2arrays.finddata, isEven, 4; // 2arrays.finddata, isEven, 6; // undefinedarrays.finddata, isEven, 6, true; // 2 // reverse find-value with optional start index and wrap around;arrays.rfinddata, isEven; // 2arrays.rfinddata, isEven, 4; // 4arrays.rfinddata, isEven, 0; // undefinedarrays.rfinddata, isEven, 0, true; // 2 // insert value at a specified index;arrays.insertdata, 0, 12; // 0arrays.insertdata, 3, 42; // 3arrays.insertdata, -9, 9; // 0arrays.insertdata, 12, 8; // 8console.logdata; // [9, 12, 0, 1, 42, 2, 3, 4, 8] // move value from one index to another;arrays.movedata, 1, 2; // truearrays.movedata, -1, 0; // falsearrays.movedata, 4, 2; // truearrays.movedata, 10, 0; // falseconsole.logdata; // [0, 2, 4, 1, 3] // remove value at a specified index;arrays.removeAtdata, 1; // 1arrays.removeAtdata, 3; // 4arrays.removeAtdata, 10; // undefinedconsole.logdata; // [0, 2, 3] // remove first occurrence of a value;arrays.removedata, 1; // 1arrays.removedata, 3; // 2arrays.removedata, 7; // -1console.logdata; // [0, 2, 4] // reverse items subject to an optional range;arrays.reversedata, 1, 3; // [0, 3, 2, 1, 4]arrays.reversedata, 3; // [0, 3, 2, 4, 1]arrays.reversedata; // [1, 4, 2, 3, 0] // rotate items by positive or negative delta;arrays.rotatedata, 2; // [2, 3, 4, 0, 1]arrays.rotatedata, -2; // [0, 1, 2, 3, 4]arrays.rotatedata, 10; // [0, 1, 2, 3, 4]arrays.rotatedata, 9; // [4, 0, 1, 2, 3] // binary search for first item >= to a value;arrays.lowerBounddata, 0, numberCmp; // 0arrays.lowerBounddata, 6, numberCmp; // 3arrays.lowerBounddata, 7, numberCmp; // 3arrays.lowerBounddata, -1, numberCmp; // 0arrays.lowerBounddata, 10, numberCmp; // 6 // binary search for first item > than a value;arrays.upperBounddata, 0, numberCmp; // 1arrays.upperBounddata, 6, numberCmp; // 3arrays.upperBounddata, 7, numberCmp; // 5arrays.upperBounddata, -1, numberCmp; // 0arrays.upperBounddata, 10, numberCmp; // 6