(arr: Array<I>, offset?: number)
| 1 | // http://jsperf.com/copy-array-inline |
| 2 | |
| 3 | export default function arrCopy<I>(arr: Array<I>, offset?: number): Array<I> { |
| 4 | offset = offset || 0; |
| 5 | const len = Math.max(0, arr.length - offset); |
| 6 | const newArr: Array<I> = new Array(len); |
| 7 | for (let ii = 0; ii < len; ii++) { |
| 8 | // @ts-expect-error We may want to guard for undefined values with `if (arr[ii + offset] !== undefined`, but ths should not happen by design |
| 9 | newArr[ii] = arr[ii + offset]; |
| 10 | } |
| 11 | return newArr; |
| 12 | } |
no test coverage detected