Sunday, March 14, 2010

Factorial in ActionScript 3

Here is factorial function in Actionscipt 3,

package{
public class MyMath{
public static function factorial(index:uint) : uint {
var total:uint = index;
if(index > 0){
total += MyMath.factorial(index - 1);
}
return total;
}
}
}


To use it
trace(MyMath.factorial(3));

Hope it helps