Skip to content

Commit a831bfe

Browse files
committed
Merge pull request #2779 from 'psixdev/master'
2 parents 4cf715f + 80d56b9 commit a831bfe

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

modules/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ export var partition = group(function(result, value, pass) {
492492
// Get the first element of an array. Passing **n** will return the first N
493493
// values in the array. The **guard** check allows it to work with `map`.
494494
export function first(array, n, guard) {
495-
if (array == null || array.length < 1) return n == null ? void 0 : [];
495+
if (array == null || array.length < 1) return n == null || guard ? void 0 : [];
496496
if (n == null || guard) return array[0];
497497
return initial(array, array.length - n);
498498
}
@@ -508,7 +508,7 @@ export function initial(array, n, guard) {
508508
// Get the last element of an array. Passing **n** will return the last N
509509
// values in the array.
510510
export function last(array, n, guard) {
511-
if (array == null || array.length < 1) return n == null ? void 0 : [];
511+
if (array == null || array.length < 1) return n == null || guard ? void 0 : [];
512512
if (n == null || guard) return array[array.length - 1];
513513
return rest(array, Math.max(0, array.length - n));
514514
}

test/arrays.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
assert.deepEqual(_.first([1, 2, 3], 5), [1, 2, 3], 'returns the whole array if n > length');
1313
var result = (function(){ return _.first(arguments); }(4, 3, 2, 1));
1414
assert.strictEqual(result, 4, 'works on an arguments object');
15-
result = _.map([[1, 2, 3], [1, 2, 3]], _.first);
16-
assert.deepEqual(result, [1, 1], 'works well with _.map');
15+
result = _.map([[1, 2, 3], [], [1, 2, 3]], _.first);
16+
assert.deepEqual(result, [1, void 0, 1], 'works well with _.map');
1717
assert.strictEqual(_.first(null), void 0, 'returns undefined when called on null');
1818
assert.deepEqual(_.first([], 10), [], 'returns an empty array when called with an explicit number of elements to return');
1919
assert.deepEqual(_.first([], 1), [], 'returns an empty array when called with an explicit number of elements to return');
@@ -70,10 +70,9 @@
7070
assert.deepEqual(_.last([1, 2, 3], 5), [1, 2, 3], 'returns the whole array if n > length');
7171
var result = (function(){ return _(arguments).last(); }(1, 2, 3, 4));
7272
assert.strictEqual(result, 4, 'works on an arguments object');
73-
result = _.map([[1, 2, 3], [1, 2, 3]], _.last);
74-
assert.deepEqual(result, [3, 3], 'works well with _.map');
73+
result = _.map([[1, 2, 3], [], [1, 2, 3]], _.last);
74+
assert.deepEqual(result, [3, void 0, 3], 'works well with _.map');
7575
assert.strictEqual(_.last(null), void 0, 'returns undefined when called on null');
76-
7776
assert.deepEqual(_.last([], 10), [], 'returns an empty array when called with an explicit number of elements to return');
7877
assert.deepEqual(_.last([], 1), [], 'returns an empty array when called with an explicit number of elements to return');
7978
assert.deepEqual(_.last(null, 5), [], 'returns an empty array when called with an explicit number of elements to return');

underscore.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

underscore.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)