Function
| Static Public Summary | ||
| public |
Passes each element of the array to the given function, and checks if all of the items make the given function return a truthy value, or if all of the items are truthy values. |
|
| public |
Passes each element of the array to the given function, and checks if any of the items makes the given function return a truthy value, or if any of the items is a truthy value. |
|
| public |
Appends the given object(s) on to the end of the given array. |
|
| public |
Searches through an array whose elements are also arrays comparing
|
|
| public |
Returns the element at the given index. |
|
| public |
By using binary search, finds an a value from this array which meets the
given condition in |
|
| public |
bsearchIndex(array: Array, callback: Function): number By using binary search, finds an index of a value from this array which
meets the given condition in |
|
| public |
Removes all elements from the array. |
|
| public |
Invokes the given function once for each element of the array. |
|
| public |
Returns a copy of the given array, with all the |
|
| public |
Appends the elements of |
|
| public |
Returns the number of elements. |
|
| public |
Calls the given callback for each item |
|
| public |
Deletes the element at the specified index, returning the removed element,
or |
|
| public |
Deletes every item of the array for which the given callback
returns |
|
| public |
difference(array: Array, otherArrays: ...*): Array Returns a new array that is a copy of the receiver, removing any items that also appear in any of the arrays given as arguments. |
|
| public |
Retrieves the value object corresponding to
each |
|
| public |
Drops first n elements from array and returns the rest of the elements in an array. |
|
| public |
Drops elements up to, but not including, the first element for which the predicate returns null or false and returns an array containing the remaining elements. |
|
| public |
Calls the given callback once for each item in the array, passing that item to the callback. |
|
| public |
Iterates the items of the array and passes their index to the callback. |
|
| public |
rbjsDelete(array: Array, object: *, block: Function): * Delets all items from the array that are equal to a given object. |
|
Static Public
public all(array: Array, predicate: Function): boolean source
import all from 'rbjs/methods/all/index.js'Passes each element of the array to the given function, and checks if all of the items make the given function return a truthy value, or if all of the items are truthy values.
Return:
| boolean | Whether all of the items in the array are truthy values, or made the given function always return truthy values. |
Example:
all([1, 'string', true], Boolean); // true
rbjs([1, 'string', true]).all(Boolean); // true
public any(array: Array, predicate: Function): boolean source
import any from 'rbjs/methods/any/index.js'Passes each element of the array to the given function, and checks if any of the items makes the given function return a truthy value, or if any of the items is a truthy value.
Return:
| boolean | Whether any of the items in the array is a truthy value, or made the given function return a truthy value. |
Example:
any([null, undefined, true], Boolean); // true
rbjs([null, undefined, true]).any(Boolean); // true
public append(array: Array, args: ...*): Array source
import append from 'rbjs/methods/append/index.js'Appends the given object(s) on to the end of the given array.
Params:
| Name | Type | Attribute | Description |
| array | Array | ||
| args | ...* | The items to append to the array |
Example:
append([1, 2], 3); // => [1, 2, 3]
append([1, 2], 3, 4, 5); // => [1, 2, 3, 4, 5]
rbjs([1, 2]).append(3); // => [1, 2, 3]
rbjs([1, 2]).append(3, 4, 5); // => [1, 2, 3, 4, 5]
public assoc(array: Array, obj: *): Array | null source
import assoc from 'rbjs/methods/assoc/index.js'Searches through an array whose elements are also arrays comparing
obj with the first element of each contained array.
Params:
| Name | Type | Attribute | Description |
| array | Array | ||
| obj | * | The object to be compared against the first element of each child array. |
Return:
| Array | null | Returns the first contained array whose first element
matches the given |
Example:
assoc([
['colors', 'red', 'blue', 'green'],
['letters', 'a', 'b', 'c'],
'foo'
], 'letters');
// => ['letters', 'a', 'b', 'c']
rbjs([
['colors', 'red', 'blue', 'green'],
['letters', 'a', 'b', 'c'],
'foo'
]).assoc('letters');
// => ['letters', 'a', 'b', 'c']
public at(array: Array, index: number): * source
import at from 'rbjs/methods/at/index.js'Returns the element at the given index. A negative index counts
from the end of the array. Returns null if the index is out of range.
Return:
| * | The array item at the given index. |
Example:
at([1, 2, 3], 1); // 2
at([1, 2, 3], -1); // 3
rbjs([1, 2, 3]).at(1); // 2
rbjs([1, 2, 3]).at(-1); // 3
public bsearch(array: Array, callback: Function): * source
import bsearch from 'rbjs/methods/bsearch/index.js' By using binary search, finds an a value from this array which meets the
given condition in O(log n) where n is the length of the array.
You can use this method in two modes: a find-minimum mode and a find-any mode. In either case, the elements of the array must be monotone (or sorted) with respect to the given callback.
In find-minimum mode (this is a good choice for typical use cases), the
callback must always return true or false, and there must be an index
i (0 <= i <= array.length) so that:
- the callback returns
falsefor any element whose index is less thani, and the callback returns
truefor any element whose index is greater than or equal toi.This method returns the
i-th element. If i is equal toarray.length, it returnsnull.In find-any mode, the callback must always return a number, and there must be two indices
iandj(0 <= i <= j <= array.length)so that:- the callback returns a positive number if
0 <= k < i, - the callback returns zero if
i <= k < j, and the callback returns a negative number if
j <= k < array.length.Under this condition, this method returns any element whose index is within
i...j. Ifiis equal toj(i.e., there is no element that satisfies the callback), this method returnsnull.You must not mix the two modes at a time; the block must always return either
true/false, or always return a number. It is undefined which value is actually picked up at each iteration.
Return:
| * | An array item that satisfies the given callback. |
Example:
bsearch([0, 4, 7, 10, 12], x => x >= 4); // => 4
bsearch([1, 2, 3, 4, 5], x => 2 - x); // => 2
rbjs([0, 4, 7, 10, 12]).bsearch(x => x >= 4); // => 4
rbjs([1, 2, 3, 4, 5]).bsearch(x => 2 - x); // => 2
public bsearchIndex(array: Array, callback: Function): number source
import bsearchIndex from 'rbjs/methods/bsearchIndex/index.js' By using binary search, finds an index of a value from this array which
meets the given condition in O(log n) where n is the length of the
array.
You can use this method in two modes: a find-minimum mode and a find-any mode. In either case, the elements of the array must be monotone (or sorted) with respect to the given callback.
In find-minimum mode (this is a good choice for typical use cases), the
callback must always return true or false, and there must be an index
i (0 <= i <= array.length) so that:
- the callback returns
falsefor any element whose index is less thani, and the callback returns
truefor any element whose index is greater than or equal toi.This method returns the index
i. If i is equal toarray.length, it returnsnull.In find-any mode, the callback must always return a number, and there must be two indices
iandj(0 <= i <= j <= array.length)so that:- the callback returns a positive number if
0 <= k < i, - the callback returns zero if
i <= k < j, and the callback returns a negative number if
j <= k < array.length.Under this condition, this method returns any index within
i...j. Ifiis equal toj(i.e., there is no element that satisfies the callback), this method returnsnull.You must not mix the two modes at a time; the block must always return either
true/false, or always return a number. It is undefined which value is actually picked up at each iteration.
Example:
bsearchIndex([0, 4, 7, 10, 12], x => x >= 4); // => 1
bsearchIndex([1, 2, 3, 4, 5], x => 2 - x); // => 1
rbjs([0, 4, 7, 10, 12]).bsearchIndex(x => x >= 4); // => 1
rbjs([1, 2, 3, 4, 5]).bsearchIndex(x => 2 - x); // => 1
public clear(array: Array): Array source
import clear from 'rbjs/methods/clear/index.js'Removes all elements from the array.
Params:
| Name | Type | Attribute | Description |
| array | Array |
Example:
clear([1, 2, 3]); // => []
rbjs([1, 2, 3]).clear(); // => []
public collect(array: Array, callback: Function): Array source
import collect from 'rbjs/methods/collect/index.js'Invokes the given function once for each element of the array. Returns an array containing the values returned by the given function.
If the callback function is not given, this returns the original array.
Return:
| Array | A new array containing the returned values of the given function, or the original array of the callback function is not given. |
Example:
collect([1, 2, 3], x => x * 2); // => [2, 4, 6]
collect(['a', 'b', 'c'], x => `${x}!`); // => ['a!', 'b!', 'c!']
rbjs([1, 2, 3]).collect(x => x * 2); // => [2, 4, 6]
rbjs(['a', 'b', 'c']).collect(x => `${x}!`); // => ['a!', 'b!', 'c!']
public compact(array: Array): Array source
import compact from 'rbjs/methods/compact/index.js' Returns a copy of the given array, with all the null and undefined
items removed.
Params:
| Name | Type | Attribute | Description |
| array | Array |
Example:
compact([1, 2, undefined, 3, null, 4, 5]); // [1, 2, 3, 4, 5]
rbjs([1, 2, undefined, 3, null, 4, 5]).compact(); // [1, 2, 3, 4, 5]
public concat(ary: Array, otherArrays: ...*): Array source
import concat from 'rbjs/methods/concat/index.js'Appends the elements of otherArrays into the given array.
Params:
| Name | Type | Attribute | Description |
| ary | Array | ||
| otherArrays | ...* |
Example:
concat([1, 2, 3], [4, 5, 6]); // => [1, 2, 3, 4, 5, 6]
concat(['a', 'b'], ['c'], ['d', 'e']) // => ['a', 'b', 'c', 'd', 'e']
rbjs([1, 2]).concat([3, 4]); // => [1, 2, 3, 4]
rbjs(['a', 'b']).concat(['c', 'd'], ['e']) // => ['a', 'b', 'c', 'd', 'e']
public count(array: Array, predicate: Function): Number source
import count from 'rbjs/methods/count/index.js'Returns the number of elements.
If an argument is given, counts the number of elements for which the object or predicate holds true
Example:
count(['a', 'b', 'c']) // => 3
count(['a', 'b', 'c'], e => e === 'b') // => 1
rbjs([1, 2, 3, 4]).count() // => 4
rbjs([1, 2, 3, 4]).count(e => e % 2 === 0) // => 2
public cycle(array: Array, callback: Function, count: Number): * source
import cycle from 'rbjs/methods/cycle/index.js' Calls the given callback for each item count times, or forever if count
is not given.
Does nothing if a non-positive number is given or the array is empty.
Returns undefined if the loop has finished without getting interrupted.
Return:
| * |
Example:
const callback = item => console.log(item);
cycle([1, 2, 3], callback); // prints: 1, 2, 3, 1, 2, 3,... forever
cycle([1, 2, 3], callback, 2); // prints: 1, 2, 3, 1, 2, 3
const callback = item => console.log(item);
rbjs([1, 2, 3]).cycle(callback); // prints: 1, 2, 3, 1, 2, 3,... forever
rbjs([1, 2, 3]).cycle(callback, 2); // prints: 1, 2, 3, 1, 2, 3
public deleteAt(array: Array, index: Number): * | null source
import deleteAt from 'rbjs/methods/deleteAt/index.js' Deletes the element at the specified index, returning the removed element,
or null if the index is out of range.
Example:
deleteAt([1, 2, 3], 1); // => 2
deleteAt([1, 2, 3], -5); // => null
rbjs([1, 2, 3]).deleteAt(1); // => 2
rbjs([1, 2, 3]).deleteAt(-5); // => null
public deleteIf(array: Array, callback: Function): Array source
import deleteIf from 'rbjs/methods/deleteIf/index.js' Deletes every item of the array for which the given callback
returns true.
Example:
deleteIf([1, 2, 3, 4, 5], x => x < 4); // => [4, 5]
rbjs([1, 2, 3, 4, 5]).deleteIf(x => x < 4); // => [4, 5]
public difference(array: Array, otherArrays: ...*): Array source
import difference from 'rbjs/methods/difference/index.js'Returns a new array that is a copy of the receiver, removing any items that also appear in any of the arrays given as arguments. The order is preserved from the original array.
Params:
| Name | Type | Attribute | Description |
| array | Array | ||
| otherArrays | ...* |
Example:
difference([1, 1, 2, 2, 3, 3, 4, 5], [1, 2, 4]); // => [ 3, 3, 5 ]
difference([1, 'c', 'yep'], [1], [ 'a', 'c' ]); // => ["yep"]
rbjs([1, 'c', 'yep']).difference([1], ['a', 'c']) // => ["yep"]
public dig(array: Array, indices: ...*): Object | null source
import dig from 'rbjs/methods/dig/index.js'Retrieves the value object corresponding to
each index objects repeatedly.
Params:
| Name | Type | Attribute | Description |
| array | Array | ||
| indices | ...* |
Example:
dig([[1, [2, 3]]], 0, 1, 1); // => 2
rbjs([[1, [2, 3]]]).dig(0, 1, 1); // => 2
public drop(array: Array, count: number): Array source
import drop from 'rbjs/methods/drop/index.js'Drops first n elements from array and returns the rest of the elements in an array.
If a negative number is given, raises a TypeError: Invalid arguments.
Example:
drop([1, 2, 3, 4, 5], 2); // => [3, 4, 5]
drop([1, 2], 3); // => []
rbjs([1, 2, 3, 4, 5]).drop(2); // => [3, 4, 5]
rbjs([1, 2]).drop(3); // => []
public dropWhile(array: Array, predicate: Function): Array source
import dropWhile from 'rbjs/methods/dropWhile/index.js'Drops elements up to, but not including, the first element for which the predicate returns null or false and returns an array containing the remaining elements.
If no predicate is given, the array is returned instead.
Example:
dropWhile([1, 2, 3, 4, 5, 0], x => x < 3); // => [3, 4, 5, 0]
rbjs([1, 2, 3, false, 5].dropWhile(x => x < 3); // => [false, 5]
public each(array: Array, callback: Function): Array source
import each from 'rbjs/methods/each/index.js'Calls the given callback once for each item in the array, passing that item to the callback.
Example:
each([1, 2, 3], callback); // calls `callback` with 1, 2, then 3
rbjs([1, 2, 3]).each(callback); // calls `callback` with 1, 2, then 3
public eachIndex(array: Array, callback: Function): Array source
import eachIndex from 'rbjs/methods/eachIndex/index.js'Iterates the items of the array and passes their index to the callback.
Example:
eachIndex(['a', 'b', 'c'], i => console.log(i)); // prints: 0 1 2
rbjs(['a', 'b', 'c']).eachIndex(i => console.log(i)); // prints: 0 1 2
public rbjsDelete(array: Array, object: *, block: Function): * source
import rbjsDelete from 'rbjs/methods/delete/index.js'Delets all items from the array that are equal to a given object.
Note that since delete is a reserved keyword in JavaScript, you must use
a different identifier when importing this method, e.g. rbjsDelete.
Return:
| * | Returns the last deleted item, or |
Example:
rbjsDelete([1, 2, 2, 3], 2); // => [1, 3]
rbjsDelete([1, 2, 2, 3], 4, () => 'hello'); // => 'hello'
rbjs([1, 2, 2, 3]).delete(2); // => [1, 3]
rbjs([1, 2, 2, 3]).delete(4, () => 'hello'); // => 'hello'
