Skip to content

hammingMany

hammingMany(reference, candidates, maxDistance?): (number | null)[]

Compute the Hamming distance from one reference string to many candidates.

Returns an array of distances, one per candidate, in the same order as the input. Returns null for candidates with a different length than the reference. If maxDistance is provided, candidates with distance exceeding the threshold will also return null (enabling early termination for better performance). maxDistance must be a non-negative integer or Infinity (no limit); NaN, negative and fractional values throw an InvalidArg error.

Parameter Type
reference string
candidates readonly string[]
maxDistance? number | null

(number | null)[]