* 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[])
| 206 | * the remaining items from the other array are included with no interleaving. |
| 207 | */ |
| 208 | function interleave<Left, Right>(left: Left[], right: Right[]): Array<Left | Right> { |
| 209 | const result: Array<Left | Right> = []; |
| 210 | |
| 211 | for (let index = 0; index < Math.max(left.length, right.length); index++) { |
| 212 | if (index < left.length) result.push(left[index]); |
| 213 | if (index < right.length) result.push(right[index]); |
| 214 | } |
| 215 | |
| 216 | return result; |
| 217 | } |
no test coverage detected