function oneAway(string1, string2) {
if (string1.length - string2.length > 1) return false;
let numDiff = 0;
if (string1.length === string2.length) {
for (let i = 0; i < string1.length; i++) {
const char1 = string1[i];
const char2 = string2[i];
if (char1 !== char2) numDiff++;
}
} else {
for (let i = 0, j = 0; i < Math.max(string1.length, string2.length) && j < Math.max(string1.length, string2.length); i++, j++) {
if (string1[i] !== string2[j]) {
numDiff++;
if (numDiff > 1) return false;
(string1.length > string2.length && i++) || j++;
}
const char1 = string1[i];
const char2 = string2[j];
if (char1 !== char2) numDiff++;
}
}
return numDiff <= 1;
}