|
391 | 391 | }; |
392 | 392 |
|
393 | 393 | // An internal function used for aggregate "group by" operations. |
394 | | - var group = function(behavior) { |
| 394 | + var group = function(behavior, partition) { |
395 | 395 | return function(obj, iteratee, context) { |
396 | | - var result = {}; |
| 396 | + var result = partition ? [[], []] : {}; |
397 | 397 | iteratee = cb(iteratee, context); |
398 | 398 | _.each(obj, function(value, index) { |
399 | 399 | var key = iteratee(value, index, obj); |
|
438 | 438 |
|
439 | 439 | // Split a collection into two arrays: one whose elements all satisfy the given |
440 | 440 | // predicate, and one whose elements all do not satisfy the predicate. |
441 | | - _.partition = function(obj, predicate, context) { |
442 | | - predicate = cb(predicate, context); |
443 | | - var pass = [], fail = []; |
444 | | - _.each(obj, function(value, key, obj) { |
445 | | - (predicate(value, key, obj) ? pass : fail).push(value); |
446 | | - }); |
447 | | - return [pass, fail]; |
448 | | - }; |
| 441 | + _.partition = group(function(result, value, pass) { |
| 442 | + result[pass ? 0 : 1].push(value); |
| 443 | + }, true); |
449 | 444 |
|
450 | 445 | // Array Functions |
451 | 446 | // --------------- |
|
0 commit comments