Skip to content

Instantly share code, notes, and snippets.

@TangoPJ
Created December 3, 2022 19:08
Show Gist options
  • Save TangoPJ/eceda42ce2bf4d03a9327ecf879c6b62 to your computer and use it in GitHub Desktop.
Save TangoPJ/eceda42ce2bf4d03a9327ecf879c6b62 to your computer and use it in GitHub Desktop.
const longestCommonPrefix = (strings) => {
if (strings.length === 1) {
return strings[0];
}
const sortedStrings = strings.sort();
const first = sortedStrings.at(0).split('');
const last = sortedStrings.at(-1);
let result = '';
// here will be a character-by-character check
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment