{"ScriptPreparationCode":"var string1 = \u0022duck\u0022;\r\nvar string2 = \u0022dark\u0022;","TestCases":[{"Name":"RegEx.test","Code":"function leven_distance(firstWord, secondWord) {\r\n if (!firstWord.length) return secondWord.length;\r\n if (!secondWord.length) return firstWord.length;\r\n\r\n return Math.min(\r\n leven_distance(firstWord.substr(1), secondWord) \u002B 1,\r\n leven_distance(secondWord.substr(1), firstWord) \u002B 1,\r\n leven_distance(firstWord.substr(1), secondWord.substr(1)) \u002B (firstWord[0] !== secondWord[0] ? 1 : 0)\r\n );\r\n}\r\nleven_distance(string1, string2);","IsDeferred":false},{"Name":"String.includes","Code":"const levenshteinDistance = (first, second) =\u003E {\r\n if (!first.length) return second.length;\r\n if (!second.length) return first.length;\r\n\r\n const distance = [];\r\n\r\n for (let i = 0; i \u003C= second.length; i\u002B\u002B) {\r\n distance[i] = [i];\r\n\r\n for (let j = 1; j \u003C= first.length; j\u002B\u002B) {\r\n if (i === 0) {\r\n distance[i][j] = j;\r\n } else {\r\n distance[i][j] = Math.min(\r\n distance[i - 1]?.[j] \u002B 1,\r\n distance[i][j - 1] \u002B 1,\r\n distance[i - 1][j - 1] \u002B (first[j - 1] === second[i - 1] ? 0 : 1)\r\n );\r\n }\r\n }\r\n }\r\n\r\n return distance[second.length][first.length];\r\n};\r\n\r\nlevenshteinDistance(string1, string2);","IsDeferred":false}]}