From 62f11f6a0cb774ce42f0d3dc0297bdbca3db860f Mon Sep 17 00:00:00 2001 From: shittu wasiu Date: Mon, 30 Jan 2023 15:43:09 +0100 Subject: [PATCH] update done --- src/brackets/index.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/brackets/index.js b/src/brackets/index.js index 96b6766..97dff8c 100644 --- a/src/brackets/index.js +++ b/src/brackets/index.js @@ -4,6 +4,28 @@ * @param {string} str The string of brackets. * @returns {"valid" | "invalid"} Whether or not the string is valid. */ -function isValid(str) {} +function isValid(str){ + let openingBrace = [ '(', '[', '{'] + let closingBrace = [ ')', ']', '}'] + let array = [] + for (let index = 0; index < str.length; index++) { + if (openingBrace.includes(str[index])) { + array.push(str[index]) + } + else if (closingBrace.indexOf(str[index]) === openingBrace.indexOf(array[array.length - 1])) { + array.pop() + } + else{ + return "invalid" + + } + } + if(array.length === 0){ + return 'valid' + } + else{ + return 'invalid' + } +} module.exports = isValid;