-
-
Notifications
You must be signed in to change notification settings - Fork 30
Array Manipulation
TheoremJS have a range of functions to help you manipulate arrays and lists.
This method will help you convert an array like [ [1, 2], [3, 4], 5 ]
to [1, 2, 3, 4, 5]
Here is how you use it:
t.flatten([
[1, 2],
[3, 4], 5
]) // => [1, 2, 3, 4, 5]
This will create a range of number starting from the number a
, going to the number b
with x
numbers in it.
If you don't have any idea of how it works, the example may help you:
t.linspace(0, 100, 10) // => [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
This will create a range of number, starting from 0
up to a number x
:
t.range(10) // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Similar as range
, but with more options (start, end, step):
t.arange(1, 11, 2) // => [ 1, 3, 5, 7, 9, 11 ]
The reshape function is the opposite of the flatten
function. It will group items in an array by x
items:
t.reshape(t.range(10), 2) /* => [
[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9],
[10]
]) */
This function is almost the same as the native Array.prototype.reverse() function, but it's not destructive.
t.reverse([1, 2, 3]) // [3, 2, 1]
Any questions? Don't hesitate to create an issue and tell me about your problem 😊.
Copyright © 2017-2018 Arthur Guiot