DEV Community

Discussion on: Write a script to identify an anagram

Collapse
 
nektro profile image
Meghan (she/her) • Edited
function isAnagram(a,b) {
    const vals = [a,b].map(x => x.split('').sort());
    return vals[0].every((v,i) => v === vals[1][i]);
}

Alternatively,

function isAnagram(a,b) {
    return new Set([a,b].map(x => x.split('').sort().join(''))).size === 1;
}