Rework of #68, to use a flag to indexOf, instead of a separate function.

This commit is contained in:
Jeremy Ashkenas
2010-12-17 10:57:12 -05:00
parent 8c2570b0ba
commit d2d6cfe667
4 changed files with 23 additions and 41 deletions

View File

@@ -84,6 +84,18 @@ $(document).ready(function() {
var result = (function(){ return _.indexOf(arguments, 2); })(1, 2, 3);
equals(result, 1, 'works on an arguments object');
equals(_.indexOf(null, 2), -1, 'handles nulls properly');
var numbers = [10, 20, 30, 40, 50], num = 35;
var index = _.indexOf(numbers, num, true);
equals(index, -1, '35 is not in the list');
numbers = [10, 20, 30, 40, 50]; num = 40;
index = _.indexOf(numbers, num, true);
equals(index, 3, '40 is in the list');
numbers = [1, 40, 40, 40, 40, 40, 40, 40, 50, 60, 70]; num = 40;
index = _.indexOf(numbers, num, true);
equals(index, 1, '40 is in the list');
});
test("arrays: lastIndexOf", function() {

View File

@@ -185,20 +185,6 @@ $(document).ready(function() {
equals(index, 3, '35 should be inserted at index 3');
});
test('collections: sortedIndexOf', function() {
var numbers = [10, 20, 30, 40, 50], num = 35;
var index = _.sortedIndexOf(numbers, num);
equals(index, -1, '35 is not in the list');
numbers = [10, 20, 30, 40, 50]; num = 40;
index = _.sortedIndexOf(numbers, num);
equals(index, 3, '40 is in the list');
numbers = [1, 40, 40, 40, 40, 40, 40, 40, 50, 60, 70]; num = 40;
index = _.sortedIndexOf(numbers, num);
equals(index, 1, '40 is in the list');
});
test('collections: toArray', function() {
ok(!_.isArray(arguments), 'arguments object is not an array');
ok(_.isArray(_.toArray(arguments)), 'arguments object converted into array');