Home > OS >  Uncaught Type Error : operation.match is not a function
Uncaught Type Error : operation.match is not a function

Time:01-29

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)

CodePudding user response:

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.

  •  Tags:  
  • Related