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

20 lines
483 B
JavaScript
Raw Normal View History

export function isAnagram(word1, word2) {
// implementar logica aqui
2022-10-29 00:44:37 +00:00
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;
}