Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit c5a4419fad5699f7908c0b2dd3749a95657de958 1 parent 43a1b48
@jdalton jdalton authored
Showing with 9 additions and 11 deletions.
  1. +7 −9 lodash.js
  2. +2 −2 perf/perf.js
View
16 lodash.js
@@ -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
4 perf/perf.js
@@ -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);
})
);
Please sign in to comment.
Something went wrong with that request. Please try again.