How to get the max\min value of an array
Posted: 28 Jan 2023, 02:20
Code: Select all
Array := [9, 3, 8, 1, 5, 7, 4, 9]
Let's help each other out
https://www.autohotkey.com/boards/
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=113208
Code: Select all
Array := [9, 3, 8, 1, 5, 7, 4, 9]
Code: Select all
Array := [9, 3, 8, 1, 5, 7, 4, 9]
MaxValue := Max(Array*)
for k, v in Array
if (v = MaxValue)
MaxIndexList .= k ","
List := RTrim(MaxIndexList, ",")
Msgbox, % "Indices with max value " MaxValue " are: " MaxIndexList
Code: Select all
A := new biga() ; requires https://github.com/biga-ahk/biga.ahk
A.max([4, 2, 8, 6])
; => 8
A.max([])
; => ""
Thank you very muchboiler wrote: ↑28 Jan 2023, 03:04Code: Select all
Array := [9, 3, 8, 1, 5, 7, 4, 9] MaxValue := Max(Array*) for k, v in Array if (v = MaxValue) MaxIndexList .= k "," List := RTrim(MaxIndexList, ",") Msgbox, % "Indices with max value " MaxValue " are: " MaxIndexList
Thanks, that's very convenient, feel like using pythonChunjee wrote: ↑28 Jan 2023, 10:17https://biga-ahk.github.io/biga.ahk/#/?id=min
https://biga-ahk.github.io/biga.ahk/#/?id=max
Code: Select all
A := new biga() ; requires https://github.com/biga-ahk/biga.ahk A.max([4, 2, 8, 6]) ; => 8 A.max([]) ; => ""