challenge-algorithms-v2.0-M.../08-isAnagram/index.js

24 lines
607 B
JavaScript
Raw Permalink Normal View History

export function isAnagram(word1, word2) {
// implementar logica aqui
2022-11-02 13:44:53 +00:00
isAnagram["roma", "amor"]
isAnagram["Buckethead" ,"Deathcubek"]
isAnagram["Twoo" ,"Woot"]
isAnagram["dumble" ,"bumble"]
isAnagram["ound" ,"round"]
isAnagram["apple" ,"pale"]
}
if ( s1.length() != s2.length() ) {
return false;
}
//tranfroma em arrays para poder ordenar
char[] c1 = s1.toCharArray();
char[] c2 = s2.toCharArray();
//ordena para garantir a comparação simplificada
Arrays.sort(c1);
Arrays.sort(c2);
//novas arrays ordenados
String sc1 = new String(c1);
String sc2 = new String(c2);
return sc1.equals(sc2);