Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Uncaught Type Error : operation.match is not a function

I am trying to get a user Input and turn that into an array of string to my token. For some reason it is not working.

For example …Compute(5*6+7) should give token = ["5","**","6","+","7"]

function splitOperation(operation) {
return operation.match(/(\d+(\.\d+)?|[+\-*/])/g);
}
  

function Compute(userInput) {
    let token = [splitOperation(userInput)];
    
    }
    
let userInput = 5*6+7
Compute(userInput)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

5*6+7 is a number.

To use "match" you need a string, use "5*6+7", if your regex is good, this should do it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading