I've used .split() dozens of times to convert strings into arrays. This is the first time I have received an unexpected result. Here, split returns an array with empty strings. This is odd, as there are no spaces in the string being split.
Is there a regex way to avoid this new and unexpected result, or need I simply remove them with a new line of code?
let infix = "(A+B)*C";
let infixArr = infix.split(/(\W)/g);
console.log(infixArr);
Yields -- > [ '', '(', 'A', '+', 'B', ')', '', '*', 'C' ]
Expected --> [ '(', 'A', '+', 'B', ')', '*', 'C' ]