* 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)
| 2228 | */ |
| 2229 | |
| 2230 | function accumulateInto(current, next) { |
| 2231 | !(next != null) ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : void 0; |
| 2232 | |
| 2233 | if (current == null) { |
| 2234 | return next; |
| 2235 | } |
| 2236 | |
| 2237 | // Both are not empty. Warning: Never call x.concat(y) when you are not |
| 2238 | // certain that x is an Array (x could be a string with concat method). |
| 2239 | if (Array.isArray(current)) { |
| 2240 | if (Array.isArray(next)) { |
| 2241 | current.push.apply(current, next); |
| 2242 | return current; |
| 2243 | } |
| 2244 | current.push(next); |
| 2245 | return current; |
| 2246 | } |
| 2247 | |
| 2248 | if (Array.isArray(next)) { |
| 2249 | // A bit too dangerous to mutate `next`. |
| 2250 | return [current].concat(next); |
| 2251 | } |
| 2252 | |
| 2253 | return [current, next]; |
| 2254 | } |
| 2255 | |
| 2256 | /** |
| 2257 | * @param {array} arr an "accumulation" of items which is either an Array or |
no test coverage detected