0

A weird thing is happening, i must be missing something but the code bellow doesn't work as expected:

  const operators = /([-+/*])/g;

  let operatorsArray = ['1','/', '*'];

  operatorsArray = operatorsArray.filter(element => element !== '');

  console.log(operators.test(operatorsArray[operatorsArray.length - 1])); //returns true

  if (operators.test(operatorsArray[operatorsArray.length - 1])) {
    console.log("I'm in!!"); //doesn't log
  }

As comment in the code, for some reason the if doesn't run.

lucas.mdiniz
  • 95
  • 1
  • 7

0 Answers0