Helpers

hammingDistance.mjs

@mr_ozio/scraper-utils · v2.5.0 · Generated April 21, 2026

Target Style

Target Style

1 exports

const

compareStrings

Target Style
export const compareStrings = ({ left = '', right = '', maxDistance = left.length } = {}) => {

Compares two strings and returns their Hamming distance.

Stops early once the distance becomes greater than maxDistance.

Target style API. Preferred for new code.

Parameters

  • [options]{ left?: string, right?: string, maxDistance?: number }

Returns

number | null

Legacy Style

Legacy Style

1 exports

const

hammingDistance

Legacy Style
export const hammingDistance = (str1 = '', str2 = '', maxDistance = str1.length) =>

Calculates the Hamming distance between strings of the same length.

Legacy API. Kept for older code and not the preferred choice for new code.

Parameters

  • [str1='']string
  • [str2='']string
  • [maxDistance=str1.length]number

Returns

number | null