I am attempting to create a JavaScript function that checks for anagrams. To keep things simple, let's assume this function only works with lowercase strings that do not contain spaces, numbers, or symbols. Why isn't the following code functioning properly?
var checkAnagram = function(word1, word2) {
var arrayWord1 = word1.split('').sort();
var arrayWord2 = word2.split('').sort();
if (arrayWord1 == arrayWord2) {
console.log("These words are anagrams");
}
else {
console.log("These words are not anagrams");
}
}