Aliases _.take() to _.first() and _.head()

This commit is contained in:
Bryan Woods
2012-03-05 12:05:39 -05:00
parent 34305bc85d
commit b3eb4a5fcb
2 changed files with 5 additions and 3 deletions

View File

@@ -12,6 +12,8 @@ $(document).ready(function() {
equal(result, 4, 'works on an arguments object.');
result = _.map([[1,2,3],[1,2,3]], _.first);
equal(result.join(','), '1,1', 'works well with _.map');
result = (function() { return _.take([1,2,3], 2); })();
equal(result.join(','), '1,2', 'aliased as take');
});
test("arrays: rest", function() {

View File

@@ -316,9 +316,9 @@
// ---------------
// Get the first element of an array. Passing **n** will return the first N
// values in the array. Aliased as `head`. The **guard** check allows it to work
// with `_.map`.
_.first = _.head = function(array, n, guard) {
// values in the array. Aliased as `head` and `take`. The **guard** check
// allows it to work with `_.map`.
_.first = _.head = _.take = function(array, n, guard) {
return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
};