mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Prefer slicing and splicing
This commit is contained in:
parent
452fdf05af
commit
5709183fe1
1 changed files with 4 additions and 10 deletions
|
@ -39,11 +39,8 @@ export function insert<T extends Identifiable>(
|
|||
const index = normalize(iterable, idOrIndex);
|
||||
|
||||
if (index >= 0) {
|
||||
iterable.items = [
|
||||
...iterable.items.slice(0, index),
|
||||
value,
|
||||
...iterable.items.slice(index),
|
||||
];
|
||||
iterable.items = iterable.items.slice();
|
||||
iterable.items.splice(index, 0, value);
|
||||
}
|
||||
|
||||
return iterable;
|
||||
|
@ -57,11 +54,8 @@ export function add<T extends Identifiable>(
|
|||
const index = normalize(iterable, idOrIndex);
|
||||
|
||||
if (index >= 0) {
|
||||
iterable.items = [
|
||||
...iterable.items.slice(0, index + 1),
|
||||
value,
|
||||
...iterable.items.slice(index + 1),
|
||||
];
|
||||
iterable.items = iterable.items.slice();
|
||||
iterable.items.splice(index + 1, 0, value);
|
||||
}
|
||||
|
||||
return iterable;
|
||||
|
|
Loading…
Reference in a new issue