Implemented _.init as per #319

This commit is contained in:
Pier Paolo Ramon
2011-10-05 14:06:18 +02:00
parent 348c93515c
commit 6d9d071b2f

View File

@@ -323,6 +323,14 @@
return slice.call(array, (index == null) || guard ? 1 : index);
};
// Returns everything but the last entry of the array. Especcialy useful on
// the arguments object. Passing **n** will return all the values in
// the array, excluding the last N. The **guard** check allows it to work with
// `_.map`.
_.init = function(array, n, guard) {
return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
};
// Get the last element of an array. Passing **n** will return the last N
// values in the array. The **guard** check allows it to work with `_.map`.
_.last = function(array, n, guard) {