Logo

Programming-Idioms

History of Idiom 135 > diff from v5 to v6

Edit summary for version 6 by steenslag:
New Ruby implementation by user [steenslag]

Version 5

2016-06-05, 18:04:18

Version 6

2016-06-13, 18:44:51

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
i = items.index(x)
items.delete_at(i) unless i.nil?