Feat:Finalizado isAnagram

This commit is contained in:
Gustavo Rallenson Gonçalves Da Silva 2022-10-28 21:44:37 -03:00
parent 0ae3211bdc
commit d98388c5d2

View File

@ -1,4 +1,20 @@
export function isAnagram(word1, word2) {
// implementar logica aqui
const anagrama = word1.toLowerCase().split('');
const palavra = word2.toLowerCase().split('');
palavra.sort((a, b) => {
return a.localeCompare(b);
})
anagrama.sort((a, b) => {
return a.localeCompare(b);
})
if( anagrama.length > palavra.length){
return false
}
for(let i = 0;i < word2.length; i++){
if(anagrama[i] !== palavra[i]){
return false;
}
}
return true;
}