I´m doing the challenge https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/telephone-number-validator and I got 3 test left to pass, with 1 I need to change somthing in my code but with the other two:
telephoneCheck(“1 555)555-5555”)
telephoneCheck(“555)-555-5555”)
It is just can be solved by checking if there are parenthesis, they are closed (so to test there aren´t only one “(” or only one ") and not it´s correspondent too )
For this I made this which works but it´s a little verbose, right:
let leftpar = /\)/
let rightpar = /\(/
// check if there are missing closing parenthesis
if (str.match(leftpar) || str.match(rightpar)){
if (str.match(leftpar)){
if (str.match(rightpar)){
1==1 //do nothing
}
else{
return false
}
}
else if (str.match(rightpar)){
if (str.match(leftpar)){
1==1 // do nothing
}
else{
return false
}
}
}
I was wondering there could be an approach less verbose.(but I don´t want to look at solutions since I have left another test to pass which forces me to change somethings in my main code)