-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleetcode.parathesis.js
41 lines (36 loc) · 1.45 KB
/
leetcode.parathesis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// misunderstood test cases. For valid output, must be changed to so that ANY open bracket is valid as long as it is CLOSED. git
function paranthesis(s) {
// input s will always be a string
//input s only comprised of bracket variations
// A valid string is comprised of a series of open, close brackets of the same type.
//Automatic end case, no open parathesis/brackets in the first position
if(s[0] ==='(' || s[0] === '[' || s[0] === '{' ){
for( i = 0; i < s.length; i++){
//conditional to exclude starting point on odd/closed index's
if(i === 0 || i % 2 == 0){
//conditonals conditional logic for false return values
if(s[i] === '(' && s[i+1] != ')' ){
console.log('case1')
return false
}
else if (s[i] === '[' && s[i+1] != ']' ){
console.log('case2')
return false
}
else if (s[i] === '{' && s[i+1] != '}' ){
console.log('case3')
return false
}
//else return true
else return true
}
}
//loop through string
}
else{
return false
}
};
console.log((paranthesis('()')), 'true')
console.log((paranthesis('(){}[]')), 'true')
console.log((paranthesis("{[]}")))