uft
    Preparing search index...

    Function filteredMap

    • Applies a filter function to the elements of the given array, and then creates a new array using the return values from calling a map function with each of the filtered elements.

      Type Parameters

      • T extends readonly unknown[]
      • S extends unknown
      • R

      Parameters

      • array: T

        The array to iterate over.

      • filter: (element: T[number], index: number) => element is S

        A function that determines whether an element should be included.

      • map: (element: S, index: number) => R

        A function to call for each included element, which returns a value.

      Returns R[]

      An array containing the results of the map function.

      const result = filteredMap(
      [1, 2, 3, 4, 5],
      (value) => value > 3,
      (value) => value * 10
      ) // type: number[]
      console.log(result) // [40, 50]
      import { isNumber } from 'uft'

      const result = filteredMap(
      ['foo', 2, 3, null],
      isNumber,
      (value) => {
      value // type: number
      return value ** 2
      }
      ) // type: number[]
      console.log(result) // [4, 9]
    • Applies a filter function to the elements of the given array, and then creates a new array using the return values from calling a map function with each of the filtered elements.

      Type Parameters

      • T extends readonly unknown[]
      • S
      • R

      Parameters

      • array: T

        The array to iterate over.

      • filter: (element: T[number], index: number) => element is S

        A function that determines whether an element should be included.

      • map: (element: AssignableTo<T[number], S>, index: number) => R

        A function to call for each included element, which returns a value.

      Returns R[]

      An array containing the results of the map function.

      const result = filteredMap(
      [1, 2, 3, 4, 5],
      (value) => value > 3,
      (value) => value * 10
      ) // type: number[]
      console.log(result) // [40, 50]
      import { isNumber } from 'uft'

      const result = filteredMap(
      ['foo', 2, 3, null],
      isNumber,
      (value) => {
      value // type: number
      return value ** 2
      }
      ) // type: number[]
      console.log(result) // [4, 9]
    • Applies a filter function to the elements of the given array, and then creates a new array using the return values from calling a map function with each of the filtered elements.

      Type Parameters

      • T extends readonly unknown[]
      • R

      Parameters

      • array: T

        The array to iterate over.

      • filter: (element: T[number], index: number) => boolean

        A function that determines whether an element should be included.

      • map: (element: T[number], index: number) => R

        A function to call for each included element, which returns a value.

      Returns R[]

      An array containing the results of the map function.

      const result = filteredMap(
      [1, 2, 3, 4, 5],
      (value) => value > 3,
      (value) => value * 10
      ) // type: number[]
      console.log(result) // [40, 50]
      import { isNumber } from 'uft'

      const result = filteredMap(
      ['foo', 2, 3, null],
      isNumber,
      (value) => {
      value // type: number
      return value ** 2
      }
      ) // type: number[]
      console.log(result) // [4, 9]