Leverage _.indexOf's fromIndex in _.difference and _.without.

Former-commit-id: 0fd092d2ee109b99a50791899e7f2d690b3852af
This commit is contained in:
John-David Dalton
2012-06-19 10:54:23 +02:00
parent b643dd074c
commit b2079b7007
2 changed files with 9 additions and 11 deletions

View File

@@ -424,7 +424,7 @@
}
}
}
// set additional template data values
// set additional template `data` values
var args = data.args,
arrayBranch = data.arrayBranch,
objectBranch = data.objectBranch,
@@ -934,7 +934,7 @@
if (!collection) {
return [];
}
if (toString.call(collection.toArray) == funcClass) {
if (collection.toArray && toString.call(collection.toArray) == funcClass) {
return collection.toArray();
}
var length = collection.length;
@@ -999,10 +999,10 @@
}
var index = -1,
length = array.length,
flattened = concat.apply(result, slice.call(arguments, 1));
flattened = concat.apply(result, arguments);
while (++index < length) {
if (indexOf(flattened, array[index]) < 0) {
if (indexOf(flattened, array[index], length) < 0) {
result.push(array[index]);
}
}
@@ -1731,12 +1731,11 @@
if (!array) {
return result;
}
var excluded = slice.call(arguments, 1),
index = -1,
var index = -1,
length = array.length;
while (++index < length) {
if (indexOf(excluded, array[index]) < 0) {
if (indexOf(arguments, array[index], 1) < 0) {
result.push(array[index]);
}
}
@@ -1911,8 +1910,7 @@
*
* var buttonView = {
* 'label': 'lodash',
* 'onClick': function() { alert('clicked: ' + this.label); },
* 'onHover': function() { console.log('hovering: ' + this.label); }
* 'onClick': function() { alert('clicked: ' + this.label); }
* };
*
* _.bindAll(buttonView);

View File

@@ -312,10 +312,10 @@
suites.push(
Benchmark.Suite('`_.difference`')
.add('Lo-Dash', function() {
lodash.difference(numbers, fourNumbers);
lodash.difference(numbers, fourNumbers, twoNumbers);
})
.add('Underscore', function() {
_.difference(numbers, fourNumbers);
_.difference(numbers, fourNumbers, twoNumbers);
})
);