Programming Questions

  • Newest
  • Popular Tags
  • Ask Question
  • Logical AND instead of OR
    I do not understand the solution with logical OR operator, so I tried using Logical AND but I'm not getting the desired output. Eg +d+=3=+s+ outputs to false, when this is a true condition. After using regex to get a string match, I'm checking if str[i-1] == '+' && str[i+1] == '+' then return true. Hope someone can shed some light on this, thank you very much! function SimpleSymbols(str) { // code goes here for(i=0;i<str.length;i++) { if (str[i].match(/[a-z]/i !== null)){ if(str[i-1] !== '+' && str[i+1] !== '+') { return true; } } } return false; } // keep this function call here SimpleSymbols(readline());
    deepMeditation posted this question on 5/3/18 | javascript, logic, simple, symbols
    Answers
  • +
  • 0
  • -
  • if you succseed with OR and NOT you can create any gate based on those two alone, and if you are feeling fancy you could even simulate a cpu ;P for AND i guess NOT(A.NOT OR B.NOT) or invert b and a then or them and then invert again
  • +
  • 0
  • -
  • Hi! In the second 'if' statement, you are testing whether the characters are *not* equal to '+', which would mean you encountered a string that fails the test. Try switching the boolean values of your return statements. Good luck!
    Log in to write an answer.