Skip to content

Instantly share code, notes, and snippets.

@rafaelrinaldi
Created August 27, 2010 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelrinaldi/553425 to your computer and use it in GitHub Desktop.
Save rafaelrinaldi/553425 to your computer and use it in GitHub Desktop.
Util to loop any array items.
package rinaldi.util
{
import flash.utils.Dictionary;
/**
*
* Util to loop any array items.
*
* @param p_data An array with all the items or just a number of loops needed.
* @param p_function Function to be fired on every data occurrences.
*
* @example
* <pre>
* import rinaldi.util.every;
*
* var arr : Array = ["yellow", "red", "green", "blue"];
*
* every(arr, function( ...args ) : void {
* var item : String = args[0] as String;
* trace(item);
* });
*
* // You can also pass just a number, like this:
* every(20, function( ...args ) : void {
* var count : Number = args[0] as Number;
* trace(count);
* });
* </pre>
*
* @see rinaldi.util
*
* @date 23/08/2010
* @author Rafael Rinaldi (rafaelrinaldi.com)
*
*/
public function every( p_data : Object, p_function : Function ) : void
{
if(p_data is Number) {
for(var count : Number = 0; count < p_data; count++)
p_function(count);
} else if(p_data is Array || p_data is Vector || p_data is Dictionary) {
for each(var item : Object in p_data)
if(item != null) p_function(item);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment