(arr: T[], index: number, elem: T)
| 1 | export function insertInto<T>(arr: T[], index: number, elem: T): T[] { |
| 2 | if (index >= arr.length) return [...arr, elem]; |
| 3 | if (index <= 0) return [elem, ...arr]; |
| 4 | |
| 5 | return arr.flatMap((x, id) => { |
| 6 | return id === index ? [elem, x] : x; |
| 7 | }); |
| 8 | } |
| 9 | |
| 10 | // fs Promise functions return errors, but no stack trace. This adds back in |
| 11 | // the stack trace. |
no outgoing calls
no test coverage detected