hopefully simple javascript question

orbi72's picture

Can't seem to get something simple to work with Javascript: I have a structure of numbers which i want to make twice as long and fill it with the same order of initial structure members.

So if arrayIN consists of [0,1,2,3] , I want the arrayOUT to look like this [0,1,2,3,0,1,2,3]. kind a like doubling the length with identical array. I think you can .concat a structure in javascript but it doesn't work with my extremely limited javascript skills

don't laugh, I'am doing something foolish here obviously:) Like not iterating the values in the array or something, but how? Can anyone help me Thank you


function (__structure arrOut) main (__structure arrIn) { var result = new Object(); var arrNew = new Array();

if(!_testMode) { arrNew.concat(arrIn,arrIn); }

result.arrOut = arrNew; return result; }

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Achim Breidenbach's picture
Re: hopefully simple javascript question

I found some things, but not the complete solution:

1) The "concat" method rather returns a new array than manipulating the one you are calling on, so you need something like this:

arrNew = arrNew.concat(arrIn, arrIn);

2) Since the input of "arrIn" is a "structure" rather than an native JS "array" you end up with an arrNew containing two items, each holding the content of arrIn.

My JavaScript skills in QC are a bit rusty, so I don't know exactly how to solve this. You may need to iterate over the complete arrIn-structure thing to add the values one by one...

I hope this gives you a bit of a direction where to go from here.

usefuldesign.au's picture
Re: hopefully simple javascript question

There are also stock patches for filtering and I think for joining QC structures, so no JS required maybe.

I think Achim is right in saying you need to iterate thru arrIn fist forwards then backwards, which means you need to iterate from 0 to arrIn.length the from arrIn.length to 0.

orbi72's picture
Re: hopefully simple javascript question

Thank you I tried with stock patches and get a severe drop in performance since the structure holds 84 items. So no solution i'll try to work out the forward and backwards iteration in JS