I am trying to solve the JS Anagram checker, I have a string first I need to separate the words and then need to check the anagrams the words may have spaces, punctuations or special character. Below is my code
module.exports = function (str) {
let mystring = str.toLowerCase()
let string1 = mystring.replace(/[.\/#!$%\^&\*;":{}=\-_`~()]/g, "");
let rsstring1 = string1.replace( /\s/g, '')
const words = rsstring1.split(",");
let str1 = words[0];
let str2 = words[1];
const sorted1 = str1.split("").sort().join("");
const sorted2 = str2.split("").sort().join("");
if(sorted1 === sorted2){
return true;
} else {
return false;;
}
}
The issue I am getting is Cannot read properties of undefined (reading 'split')