Logo

Programming-Idioms

History of Idiom 135 > diff from v19 to v20

Edit summary for version 20 by Oliphaunt:
New JS implementation by user [Oliphaunt]

Version 19

2019-09-26, 16:34:48

Version 20

2019-09-26, 16:37:07

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Code
const firstIndex = _items.indexOf(x)
const newList = _items.splice(firstIndex, 1)
Comments bubble
Removes the first instance of x from the array, leaving others intact