@trashpanda001/helpers
    Preparing search index...

    Function findValue

    • Like find, but returns the value of the function invocation instead of the element itself.

      The return value is considered to be found if fn returns a value other than CONTINUE.

      Type Parameters

      • T
      • S

      Parameters

      • array: readonly T[]

        the array to search

      • fn: (x: T) => typeof CONTINUE | S

        a function given an element that returns the final value or CONTINUE

      Returns undefined | S

      the first value found or undefined

      Find the first element that is greater than 2 and return its square.

      import { CONTINUE, findValue } from "@trashpanda001/helpers/array"

      findValue([2, 3, 4], (x) => x > 2 ? x * x : CONTINUE)
      // 9 -- found 3, result of 3 * 3
      [2, 3, 4].find((x) => x > 2)
      // 3 -- found 3, result of 3
      [2, 3, 4].findIndex((x) => x > 2)
      // 1 -- found 3, index of 1