Toolbox-XToolbox-X

Fuzzy Search

Performs a fuzzy search by matching characters in sequence against array elements.

fuzzySearch()

Performs a fuzzy search by matching characters in sequence against array elements.

Signature

fuzzySearch(
  array: T[],
  matcher: string,
  keySelector: (item: T) => string | number,
  caseInsensitive: boolean
): T | undefined

Parameters

ParameterTypeDescription
arrayT[]The collection to search.
matcherstringThe sequence to search for (e.g. 'cmn' matches 'California').
keySelector(item: T) => string | numberValue extractor function.
caseInsensitivebooleanWhether to ignore character case.

Description

The fuzzySearch method implements a flexible pattern matching algorithm that:

  • Finds items where the search characters appear in order (but not necessarily consecutively).
  • Supports both string and numeric property values.
  • Provides case sensitivity control.
  • Returns the first matching item found.

Example Usage

playground.ts

Performance Characteristics

  • Time Complexity: $O(n)$ where $n$ is array length.
  • Best For: Small to medium datasets (less than 1000 items).
  • Cache Note: Results are not cached automatically.

Use Cases

  1. Implementing type-ahead search suggestions.
  2. Finding approximate matches in user-generated content.
  3. Handling potential typos in search queries.
  4. Creating flexible filtering interfaces.

Last updated: Mon, Jun 15, 2026 06:09:51AM (UTC)

On this page