Reduce _.intersection and _.where.

Former-commit-id: b8d87f72c72c0f42e693eff67296135f0a5c548b
This commit is contained in:
John-David Dalton
2012-10-20 18:54:34 -07:00
parent 453755bfa1
commit 937bdc05c8
4 changed files with 94 additions and 103 deletions

View File

@@ -93,7 +93,7 @@
'identity': [],
'indexOf': ['sortedIndex'],
'initial': [],
'intersection': ['indexOf'],
'intersection': ['filter', 'indexOf'],
'invert': ['forOwn'],
'invoke': ['forEach'],
'isArguments': [],
@@ -154,7 +154,7 @@
'uniqueId': [],
'value': ['mixin'],
'values': ['forOwn'],
'where': ['forEach', 'forIn'],
'where': ['filter', 'forIn'],
'without': ['indexOf'],
'wrap': [],
'zip': ['max', 'pluck']
@@ -1092,23 +1092,20 @@
// replace `_.intersection`
source = source.replace(/^( +)function intersection[\s\S]+?\n\1}/m, [
' function intersection(array) {',
' var argsLength = arguments.length,',
' index = -1,',
' length = array.length,',
' result = [];',
' var args = argument,',
' argsLength = args.length;',
'',
' array: while (++index < length) {',
' var value = array[index]',
' return filter(array, function(value) {',
' if (indexOf(result, value) < 0) {',
' for (var argsIndex = 1; argsIndex < argsLength; argsIndex++) {',
' if (indexOf(arguments[argsIndex], value) < 0) {',
' continue array;',
' var length = argsLength;',
' while (--length) {',
' if (indexOf(args[length], value) < 0) {',
' return false;',
' }',
' }',
' result.push(value);',
' return true;',
' }',
' }',
' return result',
' });',
' }'
].join('\n'));