Handling an Unknown Number of Parameters : Function parameters : Function Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Function » Function parameters »

 

Handling an Unknown Number of Parameters


 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        trace(getAverage(1,2,3));
        trace(getAverage(1,2,3,4));
        trace(getAverage(1,2,3,4,5));

    }
    public function getAverage (...numbers) {
      var total = 0;
    
      for (var i = 0; i < numbers.length; i++) {
        total += numbers [i];
      }
    
      return total / numbers.length;
    }
  }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo Function
» Function parameters