Miss any of our Open RFC calls?Watch the recordings here! »

extra-array

2.10.8 • Public • Published

An array is a collection of values, stored contiguously. 🏃 📼 📦 🌔 📒

Methods as separate packages:

Methods look like:

  • swap(): doesn't modify the array itself (pure).
  • swap$(): modifies the array itself (update).

Some methods accept a map function for faster comparision (like unique). 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.

Stability: Experimental.

const array = require('extra-array');
// import * as array from 'extra-array';
// import * as array from 'https://unpkg.com/extra-array@2.8.22/index.mjs'; (deno)
 
var x = [1, 2, 3];
array.get(x, -1);
// 3
 
var x = [1, 2, 3, 4];
array.swap(x, 0, 1);
// [2, 1, 3, 4]
 
var x = [1, 2, 3, 4];
array.rotate(x, 1);
// [4, 1, 2, 3]
 
var x = [1, 3, 5, 7];
array.bsearch(x, 5);
// 2           ^ found
 
[...array.permutations([1, 2, 3])];
// [
//   [],          [ 1 ],
//   [ 2 ],       [ 3 ],
//   [ 1, 2 ],    [ 1, 3 ],
//   [ 2, 1 ],    [ 2, 3 ],
//   [ 3, 1 ],    [ 3, 2 ],
//   [ 1, 2, 3 ], [ 1, 3, 2 ],
//   [ 2, 1, 3 ], [ 2, 3, 1 ],
//   [ 3, 1, 2 ], [ 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 Counts the number of values.
fill Fills with given value.
copy Copies part of array to another.
concat Appends values from arrays.
slice Gets a part of array.
splice Removes or replaces existing values.
flat Flattens nested array to given depth.
cut Breaks array when test passes.
chunk Breaks array into chunks of given size.
cycle Gives values that cycle through array.
repeat Repeats an array given times.
reverse Reverses the array.
rotate Rotates values in array.
interleave Merges values from arrays.
min Finds smallest value.
max Finds largest entry.
range Finds smallest and largest entries.
map Updates values based on map function.
filter Keeps values which pass a test.
count Counts values which satisfy a test.
partition Segregates values by test result.
group Breaks array keeping similar values together.
split Breaks array considering test as separator.
zip Combines values from arrays.
unique Removes duplicate values.
union Gives values present in any array.
intersection Gives values present in both arrays.
difference Gives values of 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 Finds index of first value passing a test.
bsearch Binary searches leftmost value in sorted array.
find Finds first value passing a test.
findIndex Finds index of leftmost value passing a test.
sort Arranges values in an order.

nodef

Install

npm i extra-array

DownloadsWeekly Downloads

79

Version

2.10.8

License

MIT

Unpacked Size

116 kB

Total Files

6

Last publish

Collaborators

  • avatar