-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.js
42 lines (40 loc) · 971 Bytes
/
tools.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
42
function begins(needle, haystack){
return needle == haystack.substr(0, needle.length);
}
function indOfBeg(haystack, needle){
for(var i = 0; i < haystack.length; i++){
if(begins(needle, haystack[i]))
return i;
}
return -1;
}
function skipPars(str, startInd, forw){
if(forw){
var inc = 1;
var par0 = '(';
var par1 = ')';
//var endInd = str.length;
}
else{
var inc = -1;
var par0 = ')';
var par1 = '(';
//var endInd = -1;
}
var parLvl = 0;
if(str[startInd] == par0){
parLvl++;
startInd += inc;
do{
if(str[startInd] == par0)
parLvl++;
else if(str[startInd] == par1)
parLvl--;
startInd += inc;
}while(parLvl > 0 && startInd < str.length && startInd >= 0);
}
if(parLvl != 0){
err("Unbalanced parentheses")
}
return startInd;
}