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

 

senocular.com ActionScript Library

isOR.as

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

Example:
num = 10
if (num.isOR(1,2,3,4,5,6,7,8,9,10)){ // simplifies what would have been: if (num == 1 || num == 2 || ...
	// is true
}
if (num.isOR(1,2,3,4,5,6,7,8,9)){
	// is false
}

1
2
3
4
5
Number.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 value in args array return true
	return false; // if value not found, return false
}