https://github.com/harrystevens/arraygeous
A JavaScript library for lightning fast array manipulation.
https://github.com/harrystevens/arraygeous
Last synced: 18 days ago
JSON representation
A JavaScript library for lightning fast array manipulation.
- Host: GitHub
- URL: https://github.com/harrystevens/arraygeous
- Owner: HarryStevens
- License: mit
- Created: 2019-09-25T00:25:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T11:18:07.000Z (over 2 years ago)
- Last Synced: 2024-04-14T07:30:18.505Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/arraygeous
- Size: 313 KB
- Stars: 8
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# arraygeous
A JavaScript library for lightning fast array manipulation. [](https://travis-ci.org/HarryStevens/arraygeous)## Installation
### Web browser
In vanilla, a `arr` global is exported. You can use the latest version from unpkg.
```html```
If you'd rather host it yourself, download the latest release from the [`build` directory](https://github.com/HarryStevens/arraygeous/tree/master/build).### npm
```bash
npm i arraygeous -S
```
```js
const arr = require("arraygeous");
```## API
arraygeous provides three types of functions.
- [Native](#native) JavaScript functions that run faster because arraygeous uses for loops.
- [Special](#special) functions that are not included among JavaScript's native array functions.
- [Math](#math) functions that perform arithmetic on arrays.You can also call multiple functions on the same array by using arr.pipe(array). Return the result of the pipe with pipe.result().
### Native
# arr.every(array, test) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/every.js)
Returns a boolean representing whether every item in an array passes a test function.
# arr.filter(array, test) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/filter.js)
Returns a new array with every element in an array that passes a test, specified as a function.
# arr.find(array, test) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/find.js)
Returns the value of the first element in an array that passes a test, specified as a function.
# arr.findIndex(array, test) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/findIndex.js)
Returns the index of the first element in an array that passes a test, specified as a function. Returns -1 if no element passes the test.
# arr.includes(array, value[, start]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/includes.js)
Returns a boolean representing whether an array includes a value. You can specify where in the array to begin the seach with an optional start index.
# arr.map(array, accessor) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/map.js)
Returns a new array with the result of calling an accessor function for each array element.
# arr.some(array, test) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/some.js)
Returns a boolean representing whether any item in an array passes a test function.
### Special
# arr.closest(array, value[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/closest.js)
Returns the closest element in an array to a value, ignoring invalid values (null, undefined, NaN, Infinity) in the array. The array can be mapped to an optional accessor function.
# arr.count(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/count.js)
Returns an array of objects, where each object represents a unique value from an input array, according to an optional accessor function, and the number of items that value appears in the array.
# arr.flatten(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/flatten.js)
Returns a single array from an array of arrays. You can map each item in the array to the value returned by an optional accessor function.
# arr.random(array) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/random.js)
Returns a random item from an array.
# arr.sort(array[, accessor[, order]]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/sort.js)
Sorts an array. You can map each item in the array to the value returned by an optional accessor function. Defaults to ascending order, but you can return descending order by specifying the third argument, order, as the string "desc". Invalid values other than Infinity and -Infinity (null, undefined, NaN) will be moved to the end.
# arr.unique(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/unique.js)
Returns the unique values of an array. You can map each item in the array to the value returned by an optional accessor function.
### Math
# arr.cor(array[, x, y]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/cor.js)
Returns the [correlation coefficient](https://en.wikipedia.org/wiki/bivariate_correlation) of an array of paired values, where each pair is an array of two values. If your data is an array of objects, you can map each item in the array to a pair of values with optional x- and y-accessor functions.
# arr.cumsum(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/cumsum.js)
Returns the iterated cumulative sum of an array of values. You can map each item in the array to a value with an optional accessor function. Ignores invalid values (null, undefined, NaN, Infinity).
# arr.deviation(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/deviation.js)
Returns the standard deviation of an array of values. You can map each item in the array to a value with an optional accessor function. Ignores invalid values (null, undefined, NaN, Infinity).
# arr.diff(array[, accessor[, lag]]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/diff.js)
Returns lagged and iterated differences of an array of values. You can map each item in the array to a value with an optional accessor function. You can pass a third a third argument, lag, which is an integer indicating how many indices back to calculate the lag
# arr.extent(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/extent.js)
Returns the minimum and maximum, represented as [minimum, maximum], of an array of values. You can map each item in the array to a value with an optional accessor function. Ignores invalid values (null, undefined, NaN, Infinity).
# arr.max(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/max.js)
Returns the maximum of an array of values. You can map each item in the array to a value with an optional accessor function. Ignores invalid values (null, undefined, NaN, Infinity).
# arr.maxIndex(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/maxIndex.js)
Returns the index of the maximum of an array of values. You can map each item in the array to a value with an optional accessor function. Ignores invalid values (null, undefined, NaN, Infinity).
# arr.mean(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/mean.js)
Returns the mean of an array of values. You can map each item in the array to a value with an optional accessor function. Ignores invalid values (null, undefined, NaN, Infinity).
# arr.meanroll(array, n, [, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/meanroll.js)
For each item in an array of values, calculates the trailing rolling average of n items. If the index of the item is less than n, calculates the avereage of the item's value and all previous values. You can map each item in the array to a value with an optional accessor function.
# arr.median(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/median.js)
Returns the median of an array of values. You can map each item in the array to a value with an optional accessor function. Ignores invalid values (null, undefined, NaN, Infinity).
# arr.min(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/min.js)
Returns the minimum of an array of values. You can map each item in the array to a value with an optional accessor function. Ignores invalid values (null, undefined, NaN, Infinity).
# arr.minIndex(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/minIndex.js)
Returns the index of the minimum of an array of values. You can map each item in the array to a value with an optional accessor function. Ignores invalid values (null, undefined, NaN, Infinity).
# arr.mode(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/mode.js)
Returns the mode or modes, represented as an array of numbers, of an array of values. You can map each item in the array to a value with an optional accessor function. Ignores invalid values (null, undefined, NaN, Infinity). If there is no mode, returns undefined.
# arr.sum(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/sum.js)
Returns the sum of an array. You can map each item in the array to the value returned by an optional accessor function. Ignores invalid values (null, undefined, NaN, Infinity).
# arr.variance(array[, accessor]) · [Source](https://github.com/HarryStevens/arraygeous/tree/master/src/variance.js)
Returns the [variance](https://en.wikipedia.org/wiki/Variance) of an array of values. You can map each item in the array to a value with an optional accessor function. Ignores invalid values (null, undefined, NaN, Infinity).