Last active
March 23, 2020 06:42
-
-
Save ms314006/a14c427de55e192259d584dd1664bc59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var longestCommonPrefix = function(strs) { | |
const firstStr = strs[0]; | |
if (!firstStr) return ''; | |
let condition = true; | |
let count = -1; | |
while(condition) { | |
count += 1; | |
if (count === firstStr.length) { | |
condition = false; | |
} else { | |
condition = strs.every(str => ( | |
firstStr[count] === str[count] | |
)); | |
} | |
} | |
return firstStr.slice(0, count); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment