-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings_validation-parentesies.html
More file actions
executable file
·68 lines (57 loc) · 1.02 KB
/
strings_validation-parentesies.html
File metadata and controls
executable file
·68 lines (57 loc) · 1.02 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript">
function parseValid(str) {
var count=0;
var bull = true;
for(var i=0; i<str.length; i++) {
if(str[i] == "("){
count++;
} else if(str[i] == ")") {
count--;
}
if (count== -1){
bull =false;
break;
}
};
if(count != 0){
bull = false;
}
return bull;
}
console.log(parseValid("()(sdfsdf)((nn)"));
function parseValArray(string){
var LP = [];
var RP = [];
for ( i=0; i<string.length; i++ ){
if(string[i] == "(") {
LP.push(i);
} else if ( string[i] == ")" ) {
RP.push(i);
}
}
console.log(LP);
console.log(RP);
if(LP.length == RP.length) {
for ( var i = 0; i < LP.length; i++ ) {
if( LP[i] < RP[i] ) {
continue;
} else {
return false;
}
}
return true;
} else {
return false;
}
}
console.log( parseValArray('(h()) )') );
</script>
</head>
<body>
</body>
</html>