Posted By

chrisaiv on 01/25/10


Tagged

as3


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

adrianparr
tspitzr


AS3: Odd or Even


 / Published in: ActionScript 3
 

URL: http://www.bit-101.com/blog/?p=729

  1. function isEven(num)
  2. {
  3. // if(num % 2 == 0){return true;}else{return false;} //<–old
  4. return !(num%2);//shorter
  5. // return !(num & 1);//seems the fastest one
  6. }
  7. //
  8. trace(isEven(2));//–> true
  9. trace(isEven(3));//–> false
  10.  
  11. /////////////////
  12.  
  13. function isEven2(num : Number)
  14. {
  15. return num % 2 == 0;
  16. }
  17.  
  18. function isEven3(num : Number)
  19. {
  20. return num & 1 == 0;
  21. }
  22.  
  23. trace( isEven2( 5 ) );
  24. trace( isEven2( 5 ) );

Report this snippet  

You need to login to post a comment.