mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Reduce _.toArray and _.difference.
Former-commit-id: a0253006b0f38744314c449dbcffa15b67390910
This commit is contained in:
14
lodash.js
14
lodash.js
@@ -2433,10 +2433,7 @@
|
|||||||
* // => [2, 3, 4]
|
* // => [2, 3, 4]
|
||||||
*/
|
*/
|
||||||
function toArray(collection) {
|
function toArray(collection) {
|
||||||
if (!collection) {
|
if (collection && typeof collection.length == 'number') {
|
||||||
return [];
|
|
||||||
}
|
|
||||||
if (typeof collection.length == 'number') {
|
|
||||||
return (noArraySliceOnStrings ? toString.call(collection) == stringClass : typeof collection == 'string')
|
return (noArraySliceOnStrings ? toString.call(collection) == stringClass : typeof collection == 'string')
|
||||||
? collection.split('')
|
? collection.split('')
|
||||||
: slice.call(collection);
|
: slice.call(collection);
|
||||||
@@ -2529,14 +2526,11 @@
|
|||||||
* // => [1, 3, 4]
|
* // => [1, 3, 4]
|
||||||
*/
|
*/
|
||||||
function difference(array) {
|
function difference(array) {
|
||||||
var result = [];
|
|
||||||
if (!array) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = array.length,
|
length = array ? array.length : 0,
|
||||||
flattened = concat.apply(ArrayProto, arguments),
|
flattened = concat.apply(ArrayProto, arguments),
|
||||||
contains = cachedContains(flattened, length);
|
contains = cachedContains(flattened, length),
|
||||||
|
result = [];
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var value = array[index];
|
var value = array[index];
|
||||||
|
|||||||
Reference in New Issue
Block a user