Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"env": {
"browser": true,
"node": true,
"commonjs": true,
"jest": true,
"es6": true
},
"globals": {
"err": true,
"req": true,
"res": true,
"next": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"comma-dangle": ["error", "always-multiline"],
"semi": [ "error", "always" ]
}
}

Binary file added 20200210_224014.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Table of Contents
[1- code challange class 2 array shift ](https://github.com/Goorob-401-advanced-javascript/data-structures-and-algorithms/pull/3)
# Multi-bracket Validation
## Challenge summary
Multi-bracket Validation
## Challenge Description

[2- code challange class 3 array binary search ](https://github.com/Goorob-401-advanced-javascript/data-structures-and-algorithms/pull/2)
create function taht take a string as its only argument, and should return a boolean representing whether or not the brackets in the string are balanced. There are 3 types of brackets:
Round Brackets : ()
Square Brackets : []
Curly Brackets : {}

[
## Solution

![UML]
30 changes: 30 additions & 0 deletions challanges/multi-bracket-validation/multi-bracket-validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict ' ;
// used the this website to solve this problem : https://medium.com/@paulrohan/parenthesis-matching-problem-in-javascript-the-hacking-school-hyd-7d7708278911
let multiBracketValidation = (str) => {
let stack = [];

let bracketOpener = {
'{': '}',
'[': ']',
'(': ')',
};
let closed = {
'}': true,
']': true,
')': true,
};
for (let i = 0; i < str.length; i++) {
let char = str[i];
if (bracketOpener[char]) {
stack.push(char);
} else if (closed[char]) {
if (bracketOpener[stack.pop()] !== char) return false;
}
}
return stack.length === 0;
};
module.exports =multiBracketValidation ;
// let test= multiBracketValidation('{[()]');
// let test= multiBracketValidation('{[()]}');
// console.log(test);

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';
const multiBracketValidator = require('./multi-bracket-validation.js');
describe(' test multi bracket validator function ' , ()=>{
let str1 = '{([])}';
let str2 = '([{])';
it('return true if all brackets are matched', ()=>{
expect(multiBracketValidator(str1)).toBeTruthy();
});
it('return false if the brackets aren\'t matched', ()=>{
expect(multiBracketValidator(str2)).toBeFalsy();
});
});
Loading