Hi there,
Try this
a = [2,1,5,1,3];
var l:Number = a.length;
var i:Number = -1;
var b:Array = [];
var sum:Number = 0;
while (++i < l) {
sum += a[i];
trace(sum);
var tmp:Array = [];
var n:Number = a[i];
while (--n >= 0) {
tmp [n] = sum;
}
b = b.concat(tmp);
}
trace(b);
Regards,
Dimitrios Bendilas
----- Original Message -----
From: "Merrill, Jason" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <[email protected]>
Sent: Thursday, January 19, 2006 10:01 PM
Subject: [Flashcoders] expanding a second array given values of the
firstarray
Should be pretty straightforward, but I am having trouble wrapping my
head around it. I want to create an array of N length, which is expanded
according to the values of another array. What I mean is, for example:
taskSet = [2,1,5,1,3] //values of how much the new array should expand
I want to, based on the values of the taskSet array, make a running
add-up total of the values of taskSet & repeat that number in the final
array taskSet[n] times in the new taskSetExpanded array. I do not mean
just add up the values of taskSet which I already know how to do (though
by so doing, I know that also shows the length of the final array).
So (and this may be the easiest way to explain) given the array:
taskSet = [2,1,5,1,3];
The taskSetExapanded array would then become an array with these exact
values:
[2,2,3,8,8,8,8,8,9,12,12,12]
...where for example, the number 8 as seen in the array(8 comes from the
running total of 2+1+5 from TaskSet) is repeated 5 times (where 5 is the
value of taskSet[3])
..and where for example the number 9 as seen in the array (9 comes from
the running total of 2+1+5+1 from TaskSet) is repeated 1 time (where 1
is the value of taskSet[4])
Etc.
Make sense? Perhaps I over explained. I have tried numerous for loops
and never been able to get the final result I need. Any help is
appreciated. Thanks!
Jason Merrill | E-Learning Solutions | icfconsulting.com
NOTICE:
This message is for the designated recipient only and may contain privileged
or confidential information. If you have received it in error, please notify
the sender immediately and delete the original. Any other use of this e-mail
by you is prohibited.
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders