DEV Community

Discussion on: Write a script to identify an anagram

Collapse
 
danielcamargo profile image
Daniel Camargo

In javascript you can do something like this:

function isAnagram(s1, s2){
    return s1.split('').sort().toString() === s2.split('').sort().toString();
}

isAnagram('stressed', 'desserts');
// true
isAnagram('add', 'dad');
// true
isAnagram('happy', 'sad');
// false