select
@guoba-ai/utils / array / select
Function: select()
function select<T, U>(
array,
mapper,
filter): U[];Defined in: array.ts:193
Filter and map an array in one pass.
Type Parameters
T
T
U
U
Parameters
array
T[]
The array to process
mapper
(item, index) => U
Function to transform matching items
filter
(item, index) => boolean
Predicate that decides which items to include
Returns
U[]
A new array of transformed items that passed the filter
Example
select(
[1, 2, 3, 4],
v => v * 2,
v => v % 2 === 0
)
// [4, 8]