UNPKG

@linkdotnet/stringoperations

Version:

Collection of string utilities. Edit-Distances, Search and Data structures. Offers for example trie, levenshtein distance.

21 lines (20 loc) 667 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getHammingDistance = void 0; /** * * @param one First word to compare * @param two Second word to compare * @param ignoreCase Ignore case, when comparing each character */ function getHammingDistance(one, two, ignoreCase = false) { let difference = 0; for (let i = 0; i < one.length; i++) { const characterEqual = ignoreCase ? one[i].toUpperCase() === two[i].toUpperCase() : one[i] === two[i]; if (!characterEqual) { difference++; } } return difference; } exports.getHammingDistance = getHammingDistance;