max value in array  [SOLVED]

Questions about MultiCharts and user contributed studies.
turbofib
Posts: 162
Joined: 11 May 2013
Has thanked: 48 times
Been thanked: 1 time

max value in array

Postby turbofib » 29 Mar 2018

hi,
i've this array :

Array:Val[30]

i want to know the max value in this array

I would like to avoid lopping it with a for

(for counter=0 to 29......)..

How i find max value in array? thank

Zheka
Posts: 198
Joined: 13 Jan 2016
Has thanked: 8 times
Been thanked: 48 times

Re: max value in array

Postby Zheka » 29 Mar 2018

There is no way.
Why do you want to avoid looping?

turbofib
Posts: 162
Joined: 11 May 2013
Has thanked: 48 times
Been thanked: 1 time

Re: max value in array

Postby turbofib » 29 Mar 2018

yes..

User avatar
ABC
Posts: 636
Joined: 16 Dec 2006
Has thanked: 120 times
Been thanked: 359 times
Contact:

Re: max value in array  [SOLVED]

Postby ABC » 29 Mar 2018

turbofib,

using Array_Sort you can sort the array in descending order. If you need to keep the original order in the array make a copy first with Array_Copy and then sort the copy.

Regards,

ABC

Zheka
Posts: 198
Joined: 13 Jan 2016
Has thanked: 8 times
Been thanked: 48 times

Re: max value in array

Postby Zheka » 29 Mar 2018

Array_Sort loops through the array AND moves values in memory. Much more expensive than just looping and saving.

User avatar
ABC
Posts: 636
Joined: 16 Dec 2006
Has thanked: 120 times
Been thanked: 359 times
Contact:

Re: max value in array

Postby ABC » 29 Mar 2018

I agree, when you are looking for code performance the for loop will be faster. Depending on how the array is filled (and as you know the values you use to fill it), you might even save more time by just performing the loop in case the value that drops out is equal to the current highest value in the array.

Regards,

ABC


Return to “MultiCharts”