Fix reduceRight() so that if you don't pass in an initial value, the last item in the collection is used

This commit is contained in:
Elliot Winkler
2010-10-31 19:00:21 -06:00
parent 31efd854f8
commit f729769d85
2 changed files with 11 additions and 3 deletions

View File

@@ -68,8 +68,14 @@ $(document).ready(function() {
});
test('collections: reduceRight', function() {
var list = _.foldr([1, 2, 3], function(memo, num){ return memo + num; }, '');
equals(list, '321', 'can perform right folds');
var list = _.reduceRight(["foo", "bar", "baz"], function(memo, str){ return memo + str; }, '');
equals(list, 'bazbarfoo', 'can perform right folds');
var list = _.foldr(["foo", "bar", "baz"], function(memo, str){ return memo + str; }, '');
equals(list, 'bazbarfoo', 'aliased as "foldr"');
var list = _.foldr(["foo", "bar", "baz"], function(memo, str){ return memo + str; });
equals(list, 'bazbarfoo', 'default initial value');
});
test('collections: detect', function() {