Like so?

taskSet = [2,1,5,1,3];
taskSetExpanded = new Array();


for(var i=0, len=taskSet.length; i<len; i++){
        for(j=0; j<taskSet[i]; j++){
                if(!j){
                        var res = 0;
                        for(k=0; k<=i; k++){
                                res += taskSet[k];
                        }
                }
                taskSetExpanded.push(res);
        }
}

trace(taskSetExpanded);

// output: 2,2,3,8,8,8,8,8,9,12,12,12

hth
--------------
Andreas Weber
motiondraw.com


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Merrill,
Jason
Sent: Donnerstag, 19. Januar 2006 21:02
To: Flashcoders mailing list
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
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to