Saturday, 15 February 2014

actionscript 3 - How can you reverse an Array without using the reverse method in AS3? -



actionscript 3 - How can you reverse an Array without using the reverse method in AS3? -

how can reverse array without using reverse() method?

public class main extends sprite { private var _reversedlist:array = new array(); public function main() { var yourshoppinglist:array = ["milk","bread","eggs","cereal","cheese","ham"]; shoppinglist(yourshoppinglist); trace("the original array " + yourshoppinglist + " , reversed " + _reversedlist + "."); } private function shoppinglist(items:array):array { while(items.length){ var lastitem:string = items.pop(); _reversedlist.unshift(lastitem); } homecoming _reversedlist; } }

this have far. tried using _reversedlist.unshift(items.pop()); giving me error, ended creating variable, , seems fine? regardless, it's not reversing array, , i'm not sure why.

thank time , help. appreciate it.

*note: of total sail students, sense free reference this, don't re-create / paste, teachers know post , you'll penalized cheating. friendly warning.

changing

_reversedlist.unshift(lastitem);

to

_reversedlist.push(lastitem);

works me. taking lastly item , pushing in first item on new array.

arrays actionscript-3 action reverse

No comments:

Post a Comment