mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Rework of #68, to use a flag to indexOf, instead of a separate function.
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user