Longest Word in Dictionary through Deleting LeetCode solution in JavaScript
1/**2* @param {string} s3* @param {string[]} dictionary4* @return {string}5*/6var findLongestWord = function (s, dictionary) {7const getLen = (s1, s2) => {8let i = 0,9j = 0;10while (i < s1.length && j < s2.length) {11if (s1[i] == s2[j]) {12i++, j++;13} else i++;14}15if (j != s2.length) return 0;16return s2.length;17};18let ans = "",19ml = 0;20for (let word of dictionary) {21const len = getLen(s, word);22if (len > ml) {23ans = word;24ml = len;25} else if (len == ml && ans > word) {26ans = word;27}28}29return ans;30};