Array Sorting - Ascending or descending order - Forum

Forum Navigation
You need to log in to create posts and topics.

Array Sorting - Ascending or descending order

Hello Geeks,

One array is created with CreateEmptyArray Command and array is being populated using the following command.

CreateEmptyArray [citationsperpaper]

Loop 1 [serial] [lpsc]

jsPrompt "Enter Citation Count" "Coitation Count in Numbers" [ccount]

ArrayAddItem [citationsperpaper] [ccount]

Endloop

Now the Array contains values...like 22, 65, 31, 111, 09, 08, 10 depending on [serial] variable. I tried 'ArrayAlphaSort' and 'ArrayNumsort' but no way getting the order as highest value to lowest value as,

111
65
31
22
10
09
08

Any help is appreciated.

S.Ghosh

@sghoshnbu try this:

BeginJS
 $App.citationsperpaper=$App.citationsperpaper.sort(function(a, b){return b-a});
EndJS

More info here:
https://www.w3schools.com/jsref/jsref_sort.asp

Regards.

Thanks a lot @Luis...

Works great.