* Accumulates items that must not be null or undefined into the first one. This * is used to conserve memory by avoiding array allocations, and thus sacrifices * API cleanness. Since `current` can be null before being passed in and not * null after this function, make sure to assign it back to `c
(current, next)
| 1426 | */ |
| 1427 | |
| 1428 | function accumulateInto(current, next) { |
| 1429 | !(next != null) ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : void 0; |
| 1430 | |
| 1431 | if (current == null) { |
| 1432 | return next; |
| 1433 | } |
| 1434 | |
| 1435 | // Both are not empty. Warning: Never call x.concat(y) when you are not |
| 1436 | // certain that x is an Array (x could be a string with concat method). |
| 1437 | if (Array.isArray(current)) { |
| 1438 | if (Array.isArray(next)) { |
| 1439 | current.push.apply(current, next); |
| 1440 | return current; |
| 1441 | } |
| 1442 | current.push(next); |
| 1443 | return current; |
| 1444 | } |
| 1445 | |
| 1446 | if (Array.isArray(next)) { |
| 1447 | // A bit too dangerous to mutate `next`. |
| 1448 | return [current].concat(next); |
| 1449 | } |
| 1450 | |
| 1451 | return [current, next]; |
| 1452 | } |
| 1453 | |
| 1454 | /** |
| 1455 | * @param {array} arr an "accumulation" of items which is either an Array or |
no test coverage detected