Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- function bracketValidator(input){
- const splittedInput = input.split('')
- const length = splittedInput.length
- let depth = 0
- if(length % 2 !== 0) return false
- for(let i = 0; i < length; i++){
- // if(splittedInput[i] !== '{' || splittedInput[length-(i+1)] !== '}'){
- // return false
- // }
- if(splittedInput[i] === '{'){
- ++depth
- } else if(splittedInput[i] === '}'){
- --depth
- }
- if(depth === -1) return false
- }
- if(depth === 0) return true
- return false
- }
- console.log(bracketValidator('{}}{{}'))
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement