-
Check to see if var is in array
I’m working on an expression to determine the type (lowercase, uppercase, number, symbol) of the last character in a string.
Right now I’m doing something like this
par = parent.text.sourceText;
src = par.charAt(par.length-1);
lib = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
libNum = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "/", ":", ";", "(", ")", "$", "&", "@", '"', '“', '”', ".", ",", "?", "!", "'", "’"];
libSym = ["[", "]", "{", "}", "#", "%", "^", "*", "+", "=", "_", "\\", "|", "~", "<", ">", "€", "£", "¥", "•"];
if (src == " ") {
1
} else {
for (i=0;i<lib.length;i++) {
if (src == lib[i]) {
2
break
} else if (src == lib[i].toUpperCase()) {
3
break
} else {
for (n=0;n<libNum.length;n++) {
if (src == libNum[n]) {
4
break
} else {
for (s=0;s<libSym.length;s++) {
if (src == libSym[s]) {
5
break
}
}
}
}
}
}
}
This technically works, but I was wondering if there is a more efficient way to do this. This is quite slow as it requires nesting for loops within for loops.