Inserts an item at a position; the items from that position on shift up by one.
Example: [10, 20, 30, 40] with 99 at index 2 -> [10, 20, 99, 30, 40]
The list, the item, the index and whether to copy
The list with the item inserted
Inserts the same item at several positions of the original list.
Example: [10, 20, 30] with 99 at indexes [0, 2] -> [99, 10, 20, 99, 30]
The list, the item, the indexes and whether to copy
The list with the item inserted at each index
Inserts several items, the first at the first index, the second at the second, and so on, all counted on the original list.
The indexes must be in ascending order and there must be one per item, or an error is thrown. Example: [10, 20, 30] with items [88, 99] at indexes [1, 2] -> [10, 88, 20, 99, 30]
The list, the items, one index per item and whether to copy
The list with the items inserted
Adds an item at the end of the list.
Example: [10, 20, 30] adding 40 -> [10, 20, 30, 40]
The list, the item and whether to copy
The list with the item at its end
Adds an item at the start of the list.
Example: [10, 20, 30] prepending 5 -> [5, 10, 20, 30]
The list, the item and whether to copy
The list with the item at its start
Adds an item at the start or at the end of the list, as chosen.
Example: [10, 20, 30] adding 5 first -> [5, 10, 20, 30]; last -> [10, 20, 30, 5]
The list, the item, the position and whether to copy
The list with the item added
Joins several lists into one, end to end.
Example: [[1, 2], [3, 4], [5, 6]] -> [1, 2, 3, 4, 5, 6]
The lists to join and whether to copy
One list with all the items
Makes a new list with nothing in it.
Example: -> []
An empty list
Makes a list that holds the same item a number of times.
Example: 5 three times -> [5, 5, 5]
The item and how many times to repeat it
The list of repeats
Repeats a pattern of items over and over until the list reaches a given length.
Example: [1, 2, 3] to length 7 -> [1, 2, 3, 1, 2, 3, 1]
The pattern, the length to reach and whether to copy
The repeated pattern, cut to the length
Reverses the order of the items.
Example: [1, 2, 3, 4, 5] -> [5, 4, 3, 2, 1]
The list and whether to copy it first
The reversed list
Puts the items in a random order, different on every call.
Example: [1, 2, 3, 4, 5] -> perhaps [3, 1, 5, 2, 4]
The list and whether to copy it first
The shuffled list
Turns a list of lists on its side: rows become columns and columns become rows.
All the inner lists must have the same length. Example: [[0, 1, 2], [3, 4, 5]] -> [[0, 3], [1, 4], [2, 5]]
The list of lists and whether to copy it first
The transposed list of lists
Splits the list into groups of n items.
Items left over at the end are dropped unless keepRemainder is on, which adds them as a
shorter last group.
Example: [0, 1, 2, 3, 4, 5, 6, 7, 8] in groups of 3 -> [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
The list, the group size and whether to keep a partial last group
The groups, in order
Reads the item at a position in the list, counting from 0.
An index outside the list throws an error. Example: [10, 20, 30, 40] at index 2 -> 30
The list, the index and whether to copy the item
The item at that index
Reads the first item of the list.
Example: [10, 20, 30, 40] -> 10
The list and whether to copy the item
The first item
Reads the last item of the list.
Example: [10, 20, 30, 40] -> 40
The list and whether to copy the item
The last item
Keeps each item of the list with a given probability and drops the rest, so the result differs on every call.
Example: [1, 2, 3, 4, 5] with threshold 0.5 -> perhaps [1, 3, 5]
The list, the probability of keeping an item from 0 to 1, and whether to copy
The items that were kept, in their original order
Cuts out the items from a start index up to, but not including, an end index.
Example: [10, 20, 30, 40, 50] from 1 to 4 -> [20, 30, 40]
The list, the start and end indexes, and whether to copy
The items in that range
Keeps every nth item, starting from an offset.
Example: [0, 1, 2, 3, 4, 5, 6, 7, 8] with nth 3 and offset 0 -> [0, 3, 6]; with nth 2 and offset 1 -> [1, 3, 5, 7]
The list, the step, the offset to start from, and whether to copy
Every nth item, in order
Keeps the items where a repeating true/false pattern says true and drops the others.
The pattern starts over when it runs out. Example: [0, 1, 2, 3, 4, 5] with pattern [true, true, false] -> [0, 1, 3, 4]
The list and the pattern
The items the pattern kept, in order
Regroups nested lists by position: the first items of every list go together, then the second items, and so on.
level says how many levels of nesting to flatten inside each list first; 0 regroups them as
they are.
Example: [[0, 1, 2], [3, 4, 5]] at level 0 -> [[0, 3], [1, 4], [2, 5]]
The lists and the depth at which to regroup
The regrouped lists
Measures the longest list among several.
Example: [[1, 2], [3, 4, 5, 6], [7]] -> 4
The lists to measure
The length of the longest one
Tells whether an item is in the list.
Items are compared by identity, so an object is found only if the very same object is in the list. Example: [10, 20, 30, 40] includes 30 -> true, includes 50 -> false
The list and the item to look for
True when the item is in the list
Finds the position of the first occurrence of an item, or -1 when it is not in the list.
Example: [10, 20, 30, 20, 40] finding 20 -> 1, finding 50 -> -1
The list and the item to look for
The 0-based index, or -1
Measures how deeply lists are nested inside the list.
Example: [1, 2, 3] -> 1, [[1, 2], [3, 4]] -> 2, [[[1]]] -> 3
The list
The number of nesting levels
Counts the items in the list.
Example: [10, 20, 30, 40, 50] -> 5, [] -> 0
The list
The number of items
Removes the item at a position.
Example: [10, 20, 30, 40, 50] removing index 2 -> [10, 20, 40, 50]
The list, the index and whether to copy
The list without that item
Removes the first item.
Example: [10, 20, 30, 40] -> [20, 30, 40]
The list and whether to copy it first
The list without its first item
Removes the last item.
Example: [10, 20, 30, 40] -> [10, 20, 30]
The list and whether to copy it first
The list without its last item
Removes an item counted from the end: index 0 is the last item, 1 the one before it.
Example: [10, 20, 30, 40, 50] removing index 1 from the end -> [10, 20, 30, 50]
The list, the index from the end and whether to copy
The list without that item
Removes the items at several positions, all counted on the original list.
Example: [10, 20, 30, 40, 50] removing indexes [1, 3] -> [10, 30, 50]
The list, the indexes and whether to copy
The list without those items
Removes every nth item, starting from an offset.
Example: [0, 1, 2, 3, 4, 5, 6, 7, 8] with nth 3 and offset 0 -> [1, 2, 4, 5, 7, 8]
The list, the step, the offset to start from and whether to copy
The list without every nth item
Drops each item of the list with a given probability and keeps the rest, so the result differs on every call.
Example: [1, 2, 3, 4, 5] with threshold 0.5 -> perhaps [2, 4]
The list, the probability of dropping an item from 0 to 1, and whether to copy
The items that survived, in their original order
Removes repeated numbers, keeping the first occurrence of each.
Example: [1, 2, 3, 2, 4, 3, 5] -> [1, 2, 3, 4, 5]
The numbers and whether to copy
The numbers without repeats, in their original order
Removes numbers that are within a tolerance of one already kept, so values that differ only by floating-point noise count as the same.
Example: [1.0, 1.001, 2.0, 2.002, 3.0] with tolerance 0.01 -> [1.0, 2.0, 3.0]
The numbers, the tolerance and whether to copy
The numbers without near-repeats, in their original order
Removes repeated items of any kind, keeping the first occurrence of each.
Items are compared by identity, so two equal-looking objects both stay. Example: ['a', 'b', 'c', 'a', 'd', 'b'] -> ['a', 'b', 'c', 'd']
The list and whether to copy
The list without repeats, in its original order
Sorts numbers from lowest to highest, or from highest to lowest.
Example: [5, 2, 8, 1, 9] ascending -> [1, 2, 5, 8, 9]; descending -> [9, 8, 5, 2, 1]
The numbers, the direction and whether to copy
The sorted numbers
Sorts texts alphabetically, from A to Z or from Z to A.
Example: ['dog', 'apple', 'cat'] ascending -> ['apple', 'cat', 'dog']
The texts, the direction and whether to copy
The sorted texts
Sorts objects by the number held in one of their properties.
Example: [{age: 30}, {age: 20}, {age: 25}] by 'age' ascending -> [{age: 20}, {age: 25}, {age: 30}]
The objects, the property to sort by, the direction and whether to copy
The sorted objects
Weaves several lists into one by taking the first item of each in turn, then the second of each, and so on.
A shorter list simply drops out once it runs dry. An empty list of lists throws an error. Example: [[0, 1, 2], [3, 4, 5]] -> [0, 3, 1, 4, 2, 5]
The lists to weave together and whether to copy
One list with the items alternating
Reading, building and reshaping plain arrays of any kind of item. Positions are 0-based: index 0 is the first item. Most methods take a
cloneoption, on by default, that deep-copies the list first so the input is never changed; switched off, the modifying methods work on the list in place, which is faster for large data.removeAllItemsalways empties the list it is given.