Logo

Programming-Idioms

History of Idiom 135 > diff from v21 to v22

Edit summary for version 22 by joewrong:
New JS implementation by user [joewrong]

Version 21

2019-09-26, 16:44:12

Version 22

2019-09-26, 16:46:05

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
function removeItemFromList(list, item) {
  const foundIndex = list.find(li => {
    return li === item;
  });
  list.splice(foundIndex, 1);
  return list;
}