Created
April 5, 2022 17:02
-
-
Save nikonov91-dev/ad4031816324cb0eebf9c2ab54e5325e 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
function funWithAnagrams(text) { | |
let arr = [text[0]]; | |
const areTheSameAnagram = (a,b) => | |
a.split('').sort().join('') === b.split('').sort().join(''); | |
text.forEach( e => | |
!arr.find(ee => areTheSameAnagram(e, ee)) && arr.push(e) | |
) | |
return arr.sort() | |
} | |
Two strings are anagrams if they are permutations of each other. In other words, both strings have the same size and the same characters. For example, "aaagmnrs" is an anagram of "anagrams". Given an array of strings, remove each string that is an anagram of an earlier string, then return the remaining array in sorted order. | |
str = ['code', 'doce', 'ecod', 'framer', 'frame'] | |
STDIN Function | |
----- -------- | |
4 → n = 4 | |
code → text = ["code","aaagmnrs","anagrams","doce"] | |
aaagmnrs | |
anagrams | |
doce |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment