forked from M3-Academy/challenge-algorithms-v2.0
24 lines
607 B
JavaScript
24 lines
607 B
JavaScript
export function isAnagram(word1, word2) {
|
|
// implementar logica aqui
|
|
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);
|