Skip to content

Commit

Permalink
Remove fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Dec 13, 2023
1 parent 701d001 commit 08d6c47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/core/AtomList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,13 @@ import { IDisposable } from "./types";
public remove(item: T | ((i: T) => boolean)): boolean {

if (item instanceof Function) {
let index: number = 0;
let removed: boolean = false;
for (let index = 0; index <= this.length;) {
for (let index = 0; index < this.length;) {
const it = this[index];
if (item(it)) {
this.removeAt(index);
this.splice(index, 1);
AtomBinder.invokeItemsEvent(this, "remove", index, it);
AtomBinder.refreshValue(this, "length");
removed = true;
continue;
}
Expand Down
10 changes: 10 additions & 0 deletions src/tests/core/AtomListTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export class AtomListTest extends TestItem {
public removeMultiple(): void {
const list = [1, 2, 3, 4, 5];

// remove all even numbers...
list.remove((x) => x <= 2);

Assert.equals(3, list.length);
}

@Test
public removeMultipleWithFirst(): void {
const list = [1, 2, 3, 4, 5];

// remove all even numbers...
list.remove((x) => (x % 2) === 0);

Expand Down

0 comments on commit 08d6c47

Please sign in to comment.