ScriptSpot

Forum topic · General Scripting

associate number with item in array and take highest

By kredka · 2014-03-26

Description

I have I guess very stupid problem to solve and I'm out of ideas so I would be grateful for help.
I have array with filenames. it look like this:
my_files=#("textures/head.jpg","robocop/textures/head.jpg","d:/work/robocop/textures/head.jpg")

My function generate some numbers after checking each item from array like:
item 1 - number is 22, item 2 - number 11, item 3- number 7 etc.
Now I must take item(in my case fileneme) with highest number.
How can I do it, how can I associate number with item in array, then take item(in my case filename) with highest number?

Comments (1)

barigazy · 2014-03-26

It's very simple

my_files=#("textures/head.jpg","robocop/textures/head.jpg","d:/work/robocop/textures/head.jpg")
my_vals = #(22,11,7)
idx = findItem my_vals (amax my_vals)
filename = my_files[idx]