Skip to content

Instantly share code, notes, and snippets.

@lukem512
Created Dec 12, 2016
Embed
What would you like to do?
// Sort the strings alphabetically, then sort the strings by length
// Naively compare each string to the others and try to find anagrams.
function hasAnagram(strings) {
const sorted = strings.map(s => s.split("").sort().join("")).sort();
return sorted.some((s, i) => {
const sliced = sorted.slice(0, i).concat(sorted.slice(i+1));
return sliced.find(s2 => s == s2);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment