JSFiddle - React, Tailwind, and code Playground
by Vasilii Chugunov
JavaScript
/**
* @param {string[]} strs
* @return {string}
*/
var longestCommonPrefix = function(strs) {
var prefix = strs[0];
for (var i = 1; i < strs.length; i++) {
for (var j = 0; j < prefix.length; j++) {
if ((strs[i].length < j) || (prefix[j] !== strs[i][j])) {
prefix = prefix.substring(0, j);
break;
}
}
if (prefix.length == 0) {
console.log('check ?')
return '';
}
}
return prefix;
};
console.log(longestCommonPrefix(["flower", "flow", "flight"]))