/
githubmirror
/
immutable-js
Обзор
Документация
Войти
/
githubmirror
/
immutable-js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/utils/arrCopy.ts
12 строк
474 B
Julien Deniau
Migrate utiles to TypeScript (except deepEqual and mixin)
24 фев 2025, 00:23
24 фев 2025, 00:23
f472e43
Код
Авторство
О чём код?
// http://jsperf.com/copy-array-inline export default function arrCopy<I>(arr: Array<I>, offset?: number): Array<I> { offset = offset || 0; const len = Math.max(0, arr.length - offset); const newArr: Array<I> = new Array(len); for (let ii = 0; ii < len; ii++) { // @ts-expect-error We may want to guard for undefined values with `if (arr[ii + offset] !== undefined`, but ths should not happen by design newArr[ii] = arr[ii + offset]; } return newArr; }