Skip to content

Instantly share code, notes, and snippets.

@nekomeowww
Created June 25, 2020 14:35
Show Gist options
  • Save nekomeowww/4ba662c773fbf016d9b323ecc5268091 to your computer and use it in GitHub Desktop.
Save nekomeowww/4ba662c773fbf016d9b323ecc5268091 to your computer and use it in GitHub Desktop.
/**
* @param {string} word1
* @param {string} word2
* @return {number}
*/
let minDistance = function(word1, word2) {
let wordArr1 = word1.split("")
let wordArr2 = word2.split("")
let count = 0
for (let i = 0; i < wordArr1.length; i++) {
if (wordArr2[i] === undefined) {
wordArr1.slice(0, wordArr2.length + 1)
count++
}
else if (wordArr2[i] !== wordArr1[i]) {
wordArr1[i] = wordArr2[i]
count++
}
}
return count
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment