Removing items from a list #40

Closed
0x00A opened this Issue Feb 26, 2014 · 2 comments

Comments

Projects
None yet
2 participants

0x00A commented Feb 26, 2014

IDEA

What do you think about a removeItems method? This could remove a rage, for instance...

removeItems()

Remove all items.

removeItems(n)

Remove all items until n.

removeItems(Ln, Un)

Remove all items between Lower bound and Upper bound.

PROBLEM

Since there is no removeItems method, I've been looping over the items array and removing each one with removeItem, for some reason, looping forward removes only every second item! but, looping in reverse from the last one works fine, for instance...

var l = list.items.length
while(l--) {
  list.removeItem(l)
}
Owner

chjj commented Feb 26, 2014

Since there is no removeItems method, I've been looping over the items array and removing each one with removeItem, for some reason, looping forward removes only every second item! but, looping in reverse from the last one works fine, for instance...

Because every time you remove and item by index, it gets spliced out, so the items.length changes. If you want to remove all items, you could do list.setItems([]).

I'm okay with a removeItems method. That sounds like a decent idea.

0x00A commented Feb 26, 2014

Ah, I didn't think it was a real array (since there was no removeItems
mothod I assumed removeItem was abstracted to prevent the exact problem I
described). Anyway, setItems([]) would kill everything which only addresses
that use case.

On Wednesday, February 26, 2014, Christopher Jeffrey <
notifications@github.com> wrote:

Since there is no removeItems method, I've been looping over the items
array and removing each one with removeItem, for some reason, looping
forward removes only every second item! but, looping in reverse from the
last one works fine, for instance...

Because every time you remove and item by index, it gets spliced out, so
the items.length changes. If you want to remove all items, you could do
list.setItems([]).

I'm okay with a removeItems method. That sounds like a decent idea.

Reply to this email directly or view it on GitHubhttps://github.com/chjj/blessed/issues/40#issuecomment-36176833
.

Paolo Fragomeni
Founder, Here is How
http://hereishow.to

github.com/hij1nx
twitter.com/hij1nx

chjj closed this in fe08f9e Apr 26, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment