I was given a this problem at a technical interview and failed miserably in the time given. Afterwards, I sat down and worked out what I think is a good solution. The task was actually to build an angularjsAngularJS app to do this, which I did, but the guts of my solution is in javascriptJavaScript. I wanted to ask if there is a better way to do this:
// convert strings to LC for case insensitivity
// split strings into arrays
// sort the arrays (spaces will sort first and be trimmed later)
// join the arrays back into strings
// we're only concerned about the printable characters in the anagram so,
// trim() to remove any spaces and then compare the resulting strings
var str1 = this.word1.toLowerCase().split('').sort().join('').trim();
var str2 = this.word2.toLowerCase().split('').sort().join('').trim();
if (str1 === str2) {
this.isAnagram = true;
} else {
this.isAnagram = false;
}