added guards to _.first and _.rest and tests, they now work as function parameters to _.map

This commit is contained in:
Jeremy Ashkenas
2009-12-07 23:36:31 -05:00
parent 21e0cbc229
commit 2afcffb30a
2 changed files with 13 additions and 7 deletions

View File

@@ -8,6 +8,8 @@ $(document).ready(function() {
equals(_.first([1,2,3], 2).join(', '), '1, 2', 'can pass an index to first');
var result = (function(){ return _.first(arguments); })(4, 3, 2, 1);
equals(result, 4, 'works on an arguments object.');
result = _.map([[1,2,3],[1,2,3]], _.first);
equals(result.join(','), '1,1', 'works well with _.map');
});
test("arrays: rest", function() {
@@ -16,6 +18,8 @@ $(document).ready(function() {
equals(_.rest(numbers, 2).join(', '), '3, 4', 'rest can take an index');
var result = (function(){ return _(arguments).tail(); })(1, 2, 3, 4);
equals(result.join(', '), '2, 3, 4', 'aliased as tail and works on arguments object');
result = _.map([[1,2,3],[1,2,3]], _.rest);
equals(_.flatten(result).join(','), '2,3,2,3', 'works well with _.map');
});
test("arrays: last", function() {