diff --git a/src/_Problems_/balanced-parentheses.test.js b/src/_Problems_/balanced-parentheses.test.js new file mode 100644 index 00000000..9f1a2bbc --- /dev/null +++ b/src/_Problems_/balanced-parentheses.test.js @@ -0,0 +1,21 @@ +const { parentheses } = require('.'); + +describe('Parentheses', () => { + it('Should return true only when matching brackets are there', () => { + expect(parentheses("{[()]})").toEqual('Balanced'); + }); + + it('Should return false when matching brackets are not there', () => { + expect(parentheses("{[()}])").toEqual('UnBalanced'); + }); + it('Should return true only when matching brackets are there', () => { + expect(parentheses("{()})").toEqual('Balanced'); + }); + + it('Should return false when matching brackets are not there', () => { + expect(parentheses("{[}])").toEqual('UnBalanced'); + }); + + + +}); diff --git a/src/_Problems_/index.js b/src/_Problems_/index.js new file mode 100644 index 00000000..21653180 --- /dev/null +++ b/src/_Problems_/index.js @@ -0,0 +1,30 @@ +function parentheses(s) { + if(typeof s !== "string" || s.length % 2 !== 0) return false; + let i = 0; + let arr = []; + while(i