GuobaGuoba Utils

select

@guoba-ai/utils / array / select

Function: select()

function select<T, U>(
   array, 
   mapper, 
   filter): U[];

Defined in: array.ts:268

Filter and map an array in one pass.

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]

select(['a', 'b', 'c'], (_value, index) => index, (_value, index) => index !== 1)
// [0, 2]

select([], value => value, () => true) // []

On this page