Page 1 of 1

Possible to summarize arrays…?

Posted: Wed Jun 19, 2013 11:18 pm
by BuckXUK
Hello everyone



I have a script that does some fairly complicated sorting of production files by pushing segments of file names into an array and sorting on those values to determine the order to SendToData for output.



I have a request to be able to provide a production report for a given file processing operation that needs to summarize the number of distinct file sizes/media processed and also provide for total files processed.



Is it possible to summarize values in an array and obtain counts of the number of occurrences based on different values within the array?



Can anyone point me in the right direction on this? I've tried Google, but I can't get any clear indication if what I need is possible.



If not, is there some way to write the array info into an XML file and push this through an XSLT to get what I need?



Thanks in advance for any help.



Regards,



William Buckingham



Possible to summarize arrays…?

Posted: Thu Jun 20, 2013 4:42 pm
by dkelly
Nothing built-in; however, you can use Javascript associative arrays, OK actually objects but anyway, to count the number of each type.



var theItems = new Array("pdf", "pdf", "doc", "docx", "txt", "idd", "docx" );

var theItemCounts = new Array();

var i;

for (i=0; i<theItems.length; i++) {

if (theItems in theItemCounts)

theItemCounts[theItems]++;

else

theItemCounts[theItems] = 1;

}

for (i in theItemCounts)

s.log(1, i + ": " + theItemCounts);





will output the name and the number of occurrences.



Dwight Kelly

Apago, Inc.

Possible to summarize arrays…?

Posted: Thu Jun 20, 2013 9:52 pm
by BuckXUK
Hi Dwight



Thanks for the reply and suggestion.



Unfortunately my source array is more complicated and I need to be able to summarize on multiple values. Here is what my array rows look like:



["1040771_300g_DL_4-4_13.pdf","300g","DL","1040773,2]

["1040769_300g_A5_4-4_26.pdf","300g","A5","1040769,26]



And the desired report looks like this in .csv format:







Any ideas how to do this?



Thanks again.