Package Exports
- extra-array
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (extra-array) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
An array is a collection of values, stored contiguously. 🏃 📼 📦 🌔
I find the map-approach beautiful, which i learned from Haskell's sortOn()
.
You can notice that i have followed Javascript naming scheme as far as possible.
Some names are borrowed from Haskell, Python, Java, Processing.
Methods look like:
sort()
: dont modify the array itself (default).sort$()
: modifies the array for performance reasons (update).sortOn()
: accepts a map function for faster comparision (map).sortOn$()
: accepts a map function, modifies the array (map-update).
Methods as separate packages:
@extra-array/sort
: use rollup to bundle this es module.@extra-array/sort.min
: use in browser (browserify, uglify-js).
Stability: Experimental.
const array = require('extra-array');
array.get([1, 2, 3], -1);
// 3
var a = [1, 2, 3, 4];
array.swap(a, 0, 1);
// [2, 1, 3, 4]
var a = [1, 2, 3, 4];
array.rotate(a, 1);
// [4, 1, 2, 3]
array.bsearch([1, 3, 5, 7], 5);
// 2 ^ found
[...array.permutations([1, 2, 3])];
// [
// [ 1, 2, 3 ],
// [ 2, 1, 3 ],
// [ 1, 3, 2 ],
// [ 3, 1, 2 ],
// [ 2, 3, 1 ],
// [ 3, 2, 1 ]
// ]
reference
Method | Action |
---|---|
is | Checks if value is array. |
get | Gets value at index. |
set | Sets value at index. |
swap | Exchanges two values. |
index | Gets zero-based index. |
indexRange | Gets index range of part of array. |
size | Gets size of part of array. |
fill | Fills with given value. |
copy | Copies part of array to another. |
concat | Appends arrays to the end. |
slice | Gets a part of array. |
splice | Removes or replaces existing values. |
flat | Flattens nested array to given depth. |
cut | Breaks array at given indices. |
chunk | Breaks array into chunks of given size. |
cycle | Gives values that cycle through an array. |
repeat | Repeats an array given times. |
reverse | Reverses the values. |
rotate | Rotates values in array. |
interleave | Places values of an array between another. |
min | Finds smallest value. |
max | Finds largest value. |
range | Finds smallest and largest values. |
map | Updates values based on map function. |
filter | Keeps values which pass a test. |
count | Counts values which satisfy a test. |
partition | Segregates array keeping similar values together. |
group | Breaks array keeping similar values together. |
split | Breaks array considering test as separator. |
zip | Combines values from n arrays. |
unique | Removes duplicate values. |
union | Gives values present in any array. |
intersection | Gives values present in both arrays. |
difference | Gives values of an array not present in another. |
isUnique | Checks if there are no duplicate values. |
isDisjoint | Checks if arrays have no value in common. |
value | Picks an arbitrary value. |
prefix | Picks an arbitrary prefix. |
infix | Picks an arbitrary infix. |
suffix | Picks an arbitrary suffix. |
subsequence | Picks an arbitrary subsequence. |
permutation | Picks an arbitrary permutation. |
isEqual | Checks if two arrays are equal. |
compare | Compares two arrays. |
search | Searches a value from left. |
bsearch | Binary searches leftmost value in sorted array. |
find | Finds leftmost value passing the test. |
findIndex | Finds index of leftmost value passing the test. |
sort | Arranges values in an order. |