find key with highest value in array Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
trust_me

find key with highest value in array

27 Jul 2017, 06:57

Trying to find the key with the highest "value" , i am sure there is a more shorter way anyone can help me ?

Code: Select all



arr:=object("d","12","f","100","a",56)

MsgBox, % getmax(arr)

getmax(arr){
for k,v in arr
  list .=v "`n"
sort,list,NR
Loop, parse,list,`n
  {
  z:=A_LoopField
  for k,v in arr
    {
    if (v=z)
    return k
    }
  return false
  }
}
 
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: find key with highest value in array

27 Jul 2017, 07:25

The quickest way is to loop through the array and save the index if the value is larger then the value at the priviusly saved index.
Please excuse my spelling I am dyslexic.
trust_me

Re: find key with highest value in array  Topic is solved

27 Jul 2017, 07:50

Thanks :)

Code: Select all

getmax(arr){
for k,v in arr
  {
  if (v>max)
      {
      keymax:=k
      max:=v
      }
  }
return keymax
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Ineedhelplz and 319 guests