Prefer slicing and splicing

This commit is contained in:
Henrik Giesel 2021-04-24 01:48:22 +02:00
parent 452fdf05af
commit 5709183fe1

View file

@ -39,11 +39,8 @@ export function insert<T extends Identifiable>(
const index = normalize(iterable, idOrIndex); const index = normalize(iterable, idOrIndex);
if (index >= 0) { if (index >= 0) {
iterable.items = [ iterable.items = iterable.items.slice();
...iterable.items.slice(0, index), iterable.items.splice(index, 0, value);
value,
...iterable.items.slice(index),
];
} }
return iterable; return iterable;
@ -57,11 +54,8 @@ export function add<T extends Identifiable>(
const index = normalize(iterable, idOrIndex); const index = normalize(iterable, idOrIndex);
if (index >= 0) { if (index >= 0) {
iterable.items = [ iterable.items = iterable.items.slice();
...iterable.items.slice(0, index + 1), iterable.items.splice(index + 1, 0, value);
value,
...iterable.items.slice(index + 1),
];
} }
return iterable; return iterable;