From f4037272d87ffa46536078da2990edcdf41be26a Mon Sep 17 00:00:00 2001 From: TanyaKhandelwal <65648613+TanyaKhandelwal@users.noreply.github.com> Date: Tue, 31 Aug 2021 16:38:44 +0530 Subject: [PATCH] Add files via upload --- src/_Problems_/balanced-parentheses.test.js | 21 +++++++++++++++ src/_Problems_/index.js | 30 +++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/_Problems_/balanced-parentheses.test.js create mode 100644 src/_Problems_/index.js 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