* 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)
| 2444 | */ |
| 2445 | |
| 2446 | function accumulateInto(current, next) { |
| 2447 | !(next != null) ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : void 0; |
| 2448 | |
| 2449 | if (current == null) { |
| 2450 | return next; |
| 2451 | } |
| 2452 | |
| 2453 | // Both are not empty. Warning: Never call x.concat(y) when you are not |
| 2454 | // certain that x is an Array (x could be a string with concat method). |
| 2455 | if (Array.isArray(current)) { |
| 2456 | if (Array.isArray(next)) { |
| 2457 | current.push.apply(current, next); |
| 2458 | return current; |
| 2459 | } |
| 2460 | current.push(next); |
| 2461 | return current; |
| 2462 | } |
| 2463 | |
| 2464 | if (Array.isArray(next)) { |
| 2465 | // A bit too dangerous to mutate `next`. |
| 2466 | return [current].concat(next); |
| 2467 | } |
| 2468 | |
| 2469 | return [current, next]; |
| 2470 | } |
| 2471 | |
| 2472 | /** |
| 2473 | * @param {array} arr an "accumulation" of items which is either an Array or |
no test coverage detected