mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -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);
|
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;
|
||||||
|
|
Loading…
Reference in a new issue