* Adds all elements from the given source array to the given target array. * * If the source is null , undefined , * or empty, then nothing will be done. Otherwise, this has the same * semantics as * for (const s of source) target.push(s); <b
(target, source)
| 24 | * // The target is now [ 0, 1, 2, 3, 4, 5 ] |
| 25 | */ |
| 26 | function addAllToArray(target, source) { |
| 27 | if (!defined(source)) { |
| 28 | return; |
| 29 | } |
| 30 | const sourceLength = source.length; |
| 31 | if (sourceLength === 0) { |
| 32 | return; |
| 33 | } |
| 34 | const targetLength = target.length; |
| 35 | target.length += sourceLength; |
| 36 | for (let i = 0; i < sourceLength; i++) { |
| 37 | target[targetLength + i] = source[i]; |
| 38 | } |
| 39 | } |
| 40 | export default addAllToArray; |
no test coverage detected
searching dependent graphs…