> Could you post (or send me) the test script, please?
Sure, here you go.
-----------------------
function randomArray(p) {
var a = [];
for (var i = 0; i < p; i++) {
if (random(2) < random(5)) {
a.push(i);
} else {
a.push(randomArray(random(3) + 1));
}
}
return a;
}
function flatten(inArray:Array):Array {
var outArray:Array = [];
var list = inArray;
list.index = 0;
var item:Object;
var index:Number;
var len:Number;
do {
index = list.index;
len = list.length;
while (index < length) {
item = list[index++];
if (item instanceof Array) {
item.parent = list;
list.index = index;
list = item;
index = 0;
len = list.length;
} else {
outArray.push(item);
}
}
} while (list = list.parent);
return outArray;
}
Array.prototype.flatten = function(r) {
if (!r) r = [];
var n = this.length;
for (var a = 0; a < n; a++) {
if (this[a] instanceof Array) {
r.push(this[a]);
} else {
this[a].flatten(r);
}
}
return r;
};
p = 1000;
x = randomArray(p);
n = new Date().getTime();
z = x.flatten();
trace("recursive: " + (new Date().getTime() - n) + "ms");
n = new Date().getTime();
z = flatten(x);
trace("iterative: " + (new Date().getTime() - n) + "ms);
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com