Created
December 12, 2016 17:58
-
-
Save lukem512/56c8fcd2501933127b362b6e94dc27f9 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
// 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