* 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
(current, next)
| 3336 | */ |
| 3337 | |
| 3338 | function accumulateInto(current, next) { |
| 3339 | if (!(next != null)) { |
| 3340 | { |
| 3341 | throw Error( "accumulateInto(...): Accumulated items must not be null or undefined." ); |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | if (current == null) { |
| 3346 | return next; |
| 3347 | } // Both are not empty. Warning: Never call x.concat(y) when you are not |
| 3348 | // certain that x is an Array (x could be a string with concat method). |
| 3349 | |
| 3350 | |
| 3351 | if (Array.isArray(current)) { |
| 3352 | if (Array.isArray(next)) { |
| 3353 | current.push.apply(current, next); |
| 3354 | return current; |
| 3355 | } |
| 3356 | |
| 3357 | current.push(next); |
| 3358 | return current; |
| 3359 | } |
| 3360 | |
| 3361 | if (Array.isArray(next)) { |
| 3362 | // A bit too dangerous to mutate `next`. |
| 3363 | return [current].concat(next); |
| 3364 | } |
| 3365 | |
| 3366 | return [current, next]; |
| 3367 | } |
| 3368 | |
| 3369 | /** |
| 3370 | * @param {array} arr an "accumulation" of items which is either an Array or |
no outgoing calls
no test coverage detected