* 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)
| 2066 | */ |
| 2067 | |
| 2068 | function accumulateInto(current, next) { |
| 2069 | !(next != null) ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : void 0; |
| 2070 | |
| 2071 | if (current == null) { |
| 2072 | return next; |
| 2073 | } |
| 2074 | |
| 2075 | // Both are not empty. Warning: Never call x.concat(y) when you are not |
| 2076 | // certain that x is an Array (x could be a string with concat method). |
| 2077 | if (Array.isArray(current)) { |
| 2078 | if (Array.isArray(next)) { |
| 2079 | current.push.apply(current, next); |
| 2080 | return current; |
| 2081 | } |
| 2082 | current.push(next); |
| 2083 | return current; |
| 2084 | } |
| 2085 | |
| 2086 | if (Array.isArray(next)) { |
| 2087 | // A bit too dangerous to mutate `next`. |
| 2088 | return [current].concat(next); |
| 2089 | } |
| 2090 | |
| 2091 | return [current, next]; |
| 2092 | } |
| 2093 | |
| 2094 | /** |
| 2095 | * @param {array} arr an "accumulation" of items which is either an Array or |
no test coverage detected