mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
Add an optional index argument to _.last()
This makes _.last() behave the same as _.first(). Passing an optional second argument n will return the last n elements of the array.
This commit is contained in:
@@ -26,6 +26,8 @@ $(document).ready(function() {
|
||||
|
||||
test("arrays: last", function() {
|
||||
equals(_.last([1,2,3]), 3, 'can pull out the last element of an array');
|
||||
equals(_.last([1,2,3], 0).join(', '), "", 'can pass an index to last');
|
||||
equals(_.last([1,2,3], 2).join(', '), '2, 3', 'can pass an index to last');
|
||||
var result = (function(){ return _(arguments).last(); })(1, 2, 3, 4);
|
||||
equals(result, 4, 'works on an arguments object');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user