Longest Common Prefix LeetCode solution in JavaScript
1var longestCommonPrefix = function (strs) {2let commonStr = strs[0];3for (let i = 1; i < strs.length; i++) {4let currentStr = strs[i];5for (let j = 0; j < commonStr.length; j++) {6if (commonStr[j] !== currentStr[j]) {7commonStr = currentStr.slice(0, j);8break;9}10}11}12return commonStr;13};