Add all the A tasks
This commit is contained in:
parent
2dd7375f96
commit
051504d65b
1608 changed files with 18584 additions and 0 deletions
14
Task/Accumulator-factory/ActionScript/accumulator-factory.as
Normal file
14
Task/Accumulator-factory/ActionScript/accumulator-factory.as
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
//Throw an error if a non-number argument is used. (typeof evaluates to
|
||||
// "number" for both integers and reals)
|
||||
function checkType(obj:Object):void {
|
||||
if(typeof obj != "number")
|
||||
throw new ArgumentError("Expected integer or float argument. Recieved " + typeof obj);
|
||||
}
|
||||
function accumulator(sum:Object):Function {
|
||||
checkType(sum);
|
||||
return function(n:Object):Object {checkType(n); return sum += n};
|
||||
}
|
||||
var acc:Function=accumulator(2);
|
||||
trace(acc(10));
|
||||
trace(acc(4));
|
||||
trace(acc("123")); //This causes an ArgumentError to be thrown.
|
||||
Loading…
Add table
Add a link
Reference in a new issue