Issue #107: Fixing issue with _.first([1,2,3], 0) returning first element instead of empty array.

This commit is contained in:
Samuel Clay
2011-01-27 11:38:06 -05:00
parent 6b4fe66f09
commit 7aaf3616df
2 changed files with 4 additions and 2 deletions

View File

@@ -284,7 +284,7 @@
// values in the array. Aliased as `head`. The **guard** check allows it to work
// with `_.map`.
_.first = _.head = function(array, n, guard) {
return n && !guard ? slice.call(array, 0, n) : array[0];
return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
};
// Returns everything but the first entry of the array. Aliased as `tail`.
@@ -292,7 +292,7 @@
// the rest of the values in the array from that index onward. The **guard**
// check allows it to work with `_.map`.
_.rest = _.tail = function(array, index, guard) {
return slice.call(array, _.isUndefined(index) || guard ? 1 : index);
return slice.call(array, (index == null) || guard ? 1 : index);
};
// Get the last element of an array.