How to get the max\min value of an array Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
songdg
Posts: 517
Joined: 04 Oct 2017, 20:04

How to get the max\min value of an array

Post by songdg » 28 Jan 2023, 02:20

Code: Select all

Array := [9, 3, 8, 1, 5, 7, 4, 9]
How to get the max\min value of an array and its indices, as 9 is the max value and 1 and 8 is its corresponding indices.

User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: How to get the max\min value of an array  Topic is solved

Post by boiler » 28 Jan 2023, 03:04

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


User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: How to get the max\min value of an array

Post by boiler » 28 Jan 2023, 10:33

@Chunjee -- Can it tell you the indices for the max (or min) values?

songdg
Posts: 517
Joined: 04 Oct 2017, 20:04

Re: How to get the max\min value of an array

Post by songdg » 30 Jan 2023, 22:38

boiler wrote:
28 Jan 2023, 03:04

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
Thank you very much :dance:

songdg
Posts: 517
Joined: 04 Oct 2017, 20:04

Re: How to get the max\min value of an array

Post by songdg » 30 Jan 2023, 22:42

Chunjee wrote:
28 Jan 2023, 10:17
https://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([])
; => ""
Thanks, that's very convenient, feel like using python :bravo:

Post Reply

Return to “Ask for Help (v1)”