( items: T[], separator: (index: number) => T )
| 5 | * @returns An array with separators inserted between items |
| 6 | */ |
| 7 | export function interleave<T>( |
| 8 | items: T[], |
| 9 | separator: (index: number) => T |
| 10 | ): T[] { |
| 11 | const result: T[] = []; |
| 12 | items.forEach((item, index) => { |
| 13 | result.push(item); |
| 14 | if (index < items.length - 1) { |
| 15 | result.push(separator(index)); |
| 16 | } |
| 17 | }); |
| 18 | return result; |
| 19 | } |
no outgoing calls
no test coverage detected