in-place
Fast, low-garbage functions for manipulating arrays in-place.
$ npm install in-place
var inPlace = ;
Methods
All these methods directly modify the array you pass in. They never allocate new arrays.
map(array, callback[, thisArg])
Alternative to array.map(callback[, thisArg])
.
var array = 1 2 3 4 5; inPlace; console; // [2, 4, 6, 8, 10]
filter(array, callback[, thisArg])
Alternative to array.filter(callback[, thisArg])
.
var array = 1 121 52 22 6; inPlace; console; // [1, 5.2, 6]
deleteIndex(array, index)
- Very fast method to delete a single item by index.
- Does not preserve the original order.
- If you care about keeping the array in order, use
array.splice(index, 1)
.
var foo = 1 2 3 4 5 6 7; inPlace; console; // [1, 2, 7, 4, 5, 6]
dedupe(array)
- Removes any repeated items (using
===
for comparison) from the array. - The last of each set of duplicate values is retained.
var array = 1 2 2 5 1 6 2; inPlace; console; // [5, 1, 6, 2];
dedupeSorted(array)
- Like
inPlace.dedupe(array)
but faster – for use when you know the array is already sorted (i.e.array[n] <= array[n + 1]
).
var array = 1 2 2 3 5 6 6 6; inPlace; console; // [1, 2, 3, 5, 6]
concat(array, ...values)
Alternative to array.concat(...values)
.
var array = 1 2; inPlace; console; // [1, 2, 3, 4, 5, 6, 7, 8]