Javascript / Merge 2 structures while preserving index names

franz's picture

Hi, i'm using a nice little javascript to merge multiple structures. While the patch is working great (thanks to cwright !), it doesn't RETAIN ORIGINAL index NAMES .... making it rather useless...

Any help would make my day.

Here's the JS:

var result = new Object();
function (__structure outStruct) main (__structure inputStruct[3])
{
        result.outStruct = new Object();
 
        var i = 0;
        for(item in inputStruct[0])
                result.outStruct[""+i++] = inputStruct[0][item];
        for(item in inputStruct[1])
                result.outStruct[""+i++] = inputStruct[1][item];
        for(item in inputStruct[2])
                result.outStruct[""+i++] = inputStruct[2][item];
        return result;
}

Comment viewing options

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

cwright's picture
Re: Javascript / Merge 2 structures while preserving index ...

Can you supply a sample composition, and some sample inputs/expected outputs?

franz's picture
Re: Javascript / Merge 2 structures while preserving index ...

here's an example. Output structure should show indexes named "foo" and "bar". It actually doesn't.

the other example is what i'm trying to achieve.

PreviewAttachmentSize
Structure CONCAT.qtz24.65 KB
Structure CONCAT easier.qtz3.46 KB

franz's picture
Re: Javascript / Merge 2 structures while preserving index ...

sorted:

result.outStruct[""+item] = inputStruct[0][item];

franz's picture
Re: Javascript / Merge 2 structures while preserving index names

for those interested, I've just released a QCplugin that does the job.

1024 blog