Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

isOR.as

Name: isOR() logical string OR (||) simplifier 
Author: senocular: www.senocular.com
Date: 1899-12-31T00:04:52.100
Documentation:
String isOR: reduces multiple uses of || in an comparison when
dealing with the same string.
Arguments:
- a list seperated by commas of any number of strings to be compared with this

...number version similar

Example:
str = "j"
if (str.isOR("a","b","c","d","e","f","g","h","i","j")){ // simplifies what would have been: if (str == "a" || str == "b" || ...
	// is true
}
if (str.isOR("a","b","c","d","e","f","g","h","i")){
	// is false
}

1
2
3
4
5
String.prototype.isOR = function(args){
	var i, l = arguments.length; // local vars
	for (i=0; i<l; i++) if (this == arguments[i]) return true; // if this string in args array return true
	return false; // if string not found, return false
}