Returns the first element of the array. If the array is empty, the first form returns undefined
. See also #last for the opposite effect.
var dummy = ['a', 'b', 'c', 'd'];
dummy.first(); #=> `a`
Returns the last element of self. If the array is empty, the first form returns undefined
.
var dummy = ['a', 'b', 'c', 'd'];
dummy.last(); #=> 'd'
Returns true if self contains no elements.
[].empty() #=> true
Removes all elements from self.
var dummy = ['a', 'b', 'c', 'd'];
dummy.clear(); #=> []
Alias for .length
.
Choose a random element or n random elements from the array.
If the array is empty the first form returns undefined
.
var dummy = ['a', 'b', 'c', 'd'];
dummy.sample(); #=> 'c'
Returns a copy of self with all undefined
or null
elements removed.
var dummy = ['a', undefined, null, 'd'];
dummy.compact(); #=> ['a', 'd']
Returns true
if the given object is present in self (that is, if any element === object), otherwise returns false
.
var dummy = ['a', 'b', 'c', 'd'];
dummy.include('b') #=> true
Returns first n elements from the array.
var dummy = ['a', 'b', 'c', 'd'];
dummy.take(2) #=> ['a', 'b']
Iterates the given block int times, passing in values from zero to int - 1.
(5).times(function (i) {
console.log(i);
});
#=> 0 1 2 3 4
Iterates the given block, passing in integer values from int up to and including limit.
(1).upto(5, function (i) {
console.log(i);
});
#=> 1 2 3 4 5
Iterates the given block, passing decreasing values from int down to and including limit.
(5).downto(1, function (i) {
console.log(i);
});
#=> 5 4 3 2 1