mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 08:57:49 +00:00
Add init(), tail() and reverse() Array functions. Alias first() to head();
This commit is contained in:
@@ -305,6 +305,29 @@
|
||||
while (i--) if (array[i] === item) return i;
|
||||
return -1;
|
||||
};
|
||||
|
||||
// Returns everything but the first entry of the array. Conceptually the
|
||||
// same as calling shift(), but doesn't mutate the array passed in.
|
||||
_.tail = function(array) {
|
||||
var tail = _.clone(array);
|
||||
tail.shift();
|
||||
return tail;
|
||||
};
|
||||
|
||||
// Returns everything but the last entry of the array. Conceptually the
|
||||
// same as calling pop(), but doesn't mutate the array passed in.
|
||||
_.init = function(array) {
|
||||
var init = _.clone(array);
|
||||
init.pop();
|
||||
return init;
|
||||
};
|
||||
|
||||
// Returns a new array, with the entries or the passed-in array in reverse
|
||||
// order.
|
||||
_.reverse = function(array) {
|
||||
var reverse = _.clone(array);
|
||||
return reverse.reverse();
|
||||
};
|
||||
|
||||
/* ----------------------- Function Functions: -----------------------------*/
|
||||
|
||||
@@ -501,6 +524,7 @@
|
||||
|
||||
/*------------------------------- Aliases ----------------------------------*/
|
||||
|
||||
_.head = _.first;
|
||||
_.forEach = _.each;
|
||||
_.foldl = _.inject = _.reduce;
|
||||
_.foldr = _.reduceRight;
|
||||
|
||||
Reference in New Issue
Block a user