/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function getSumOfArrayRange($array:Array, $indexStart:int, $indexLength:int):Number { var rangeTotal:Number = 0; if ($indexStart + $indexLength > $array.length) { $indexLength = $array.length - $indexStart; } for (var i:int = 0; i<$indexLength; i++) { rangeTotal += Number($array[i+$indexStart]); } return rangeTotal; } var myArray:Array = [10,21,32,43,54,65,76]; var sumOfRange:Number = getSumOfArrayRange(myArray, 1, 3); trace("sumOfRange: "+sumOfRange); // OUTPUT // sumOfRange: 96 // In this example, the following values were added together ... // 21 + 32 + 43