AnsweredAssumed Answered

How to get second, third, etc largest values in an array using Arcade?

Question asked by rtehranifar_NYCEDCMGIS on Jun 29, 2020
Latest reply on Jul 7, 2020 by rtehranifar_NYCEDCMGIS

I am trying to create a popup using arcade that shows in descending order the values across four fields in one feature.

for example, 

geography A103054020


I would like to have access to an array (or other data types) that I can use in a popup. The user would click on a feature on the popup would show the following:

1. $feature.col4

2. $feature.col2

3. $feature.col5

4. $feature.col1

5, $feature.col3


I have less of an issue presenting in popup, but getting the data ordered. I dont think there is a slice or filter available in arcade.

There is OrderBy function, but that goes down a column vs across a row

so far I have the following in my code to get the max value


var col1 = $feature.col1

var col2 = $feature.col2

var col3 = $feature.col3

var col4 = $feature.col4

var col5 = $feature.col5


var max_val = (col1, col2,  col3, col4, col5)


My logic tells me that I should remove the current max value and then continue to run max function until I have the last one. But I cant seem to find an easy solution. I can run a long if statement, but hoping there is an easier option.