* Interleaves the two arrays, starting with the first item on the left, then the first item * on the right, second item from the left, and so on. When the first array's items are exhausted, * the remaining items from the other array are included with no interleaving.
(left: Left[], right: Right[])
| 199 | * the remaining items from the other array are included with no interleaving. |
| 200 | */ |
| 201 | function interleave<Left, Right>(left: Left[], right: Right[]): Array<Left | Right> { |
| 202 | const result: Array<Left | Right> = []; |
| 203 | |
| 204 | for (let index = 0; index < Math.max(left.length, right.length); index++) { |
| 205 | if (index < left.length) result.push(left[index]); |
| 206 | if (index < right.length) result.push(right[index]); |
| 207 | } |
| 208 | |
| 209 | return result; |
| 210 | } |
no test coverage detected
searching dependent graphs…