Logo

Programming-Idioms

History of Idiom 247 > diff from v14 to v15

Edit summary for version 15 by Vaporox:
New JS implementation by user [Vaporox]

Version 14

2021-01-07, 09:49:09

Version 15

2021-01-23, 23:43:06

Idiom #247 Filter list in-place

Remove all the elements from list x that don't satisfy the predicate p, without allocating a new list.
Keep all the elements that do satisfy p.

For languages that don't have mutable lists, refer to idiom #57 instead.

Idiom #247 Filter list in-place

Remove all the elements from list x that don't satisfy the predicate p, without allocating a new list.
Keep all the elements that do satisfy p.

For languages that don't have mutable lists, refer to idiom #57 instead.

Variables
x,p
Variables
x,p
Extra Keywords
keep conserve preserve mutable
Extra Keywords
keep conserve preserve mutable
Code
for (const [key, value] of x.entries()) {
	if (!p(value)) x.splice(key, 1);
}