Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var values = ['{([]])}','{[}]}','{(][])}', '{()}'];
- function Braces(values)
- {
- //Creating variables and array
- var i,ch,x,corrBrace;
- var lenV = values.length;
- var result = [];
- var temp = [];
- var opnBraces = [ '[' , '{', '('];
- var clsBraces = [ ']' , '}', ')'];
- for(x = 0; x < lenV; x++ )
- {
- stk = values[x];
- var lenS = stk.length;
- for(i = 0; i < lenS; i++)
- {
- ch = stk[i]; //Puts the values in ch
- if(opnBraces.indexOf(ch) > -1)
- {
- temp.push(ch);
- }
- else if(clsBraces.indexOf(ch) > -1)
- {
- corrBrace = opnBraces[clsBraces.indexOf(ch)];
- if(temp.length === 0 || (temp.pop() !== corrBrace))
- {
- result.push("NO");
- break;
- }
- }
- }
- if(i == lenS)
- {
- result.push("YES");
- }
- }
- return (result);
- }
Add Comment
Please, Sign In to add comment