Created
June 9, 2016 01:10
-
-
Save mdrmtz/71eb1c91218f704163d7067796e8a4fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Implement function verify (text) which checks whether brackets within text are correctly nested. | |
| * You need to consider brackets of three kinds: (), [], <>. | |
| */ | |
| (function() { | |
| function verify(value){ | |
| var str = ''; | |
| value = value.replace(/[^\(\)\[\]\<\>]/g,''); | |
| while(value.length != str.length) { | |
| str = value; | |
| value = value.replace('()','').replace('[]','').replace('<>',''); | |
| } | |
| return !value.length; | |
| } | |
| console.log(verify("---(++++)----")); //true | |
| console.log(verify("")); //true | |
| console.log(verify("before ( middle []) after")); //true | |
| console.log(verify(")(")); //false | |
| console.log(verify("}{")); //true | |
| console.log(verify("<( >)")); //false | |
| console.log(verify("( [ <> () ] <> )")); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment