|
DustyShouri Novice
Joined: 29 Oct 2004 Posts: 34
|
Posted: Thu Aug 11, 2005 11:12 pm
Arrays and their indexs |
I was wondering if there was a way to grab the index with the highest value in an array? I don't mean the value of the highest index, just the highest index?
#VAR test %array{0,1,0,5,0}
Is there anyway I could get it to return 4? |
|
|
|
Carabas GURU
Joined: 28 Sep 2000 Posts: 434 Location: USA
|
Posted: Fri Aug 12, 2005 11:31 am |
#HELP %arrhigh
|
|
_________________ Carabas |
|
|
|
DustyShouri Novice
Joined: 29 Oct 2004 Posts: 34
|
Posted: Fri Aug 12, 2005 6:30 pm |
That only grabs the length of the array.
|
|
|
|
Carabas GURU
Joined: 28 Sep 2000 Posts: 434 Location: USA
|
Posted: Fri Aug 12, 2005 6:39 pm |
If I understand your original question, this is the function you are looking for.
Quote: |
Syntax: %arrhigh(arrayname)
return the index value of the last element in the array |
#VAR test %array(0,1,0,5,0)
#SH %arrhigh(test)
Output: 4 |
|
_________________ Carabas |
|
|
|
DustyShouri Novice
Joined: 29 Oct 2004 Posts: 34
|
Posted: Fri Aug 12, 2005 9:40 pm |
Nope, that gives the number of indexes in the array. I was looking to somehow find the index with the largest value in the array.
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Fri Aug 12, 2005 10:40 pm |
You'll have to build your own on that one. It's basically a modified sort function, so it shouldn't be that hard to hammer out.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Carabas GURU
Joined: 28 Sep 2000 Posts: 434 Location: USA
|
Posted: Sat Aug 13, 2005 12:33 am |
DustyShouri wrote: |
Nope, that gives the number of indexes in the array. |
Perhaps I am completely misunderstanding your question, but I thought you wanted the number of elements.
DustyShouri wrote: |
#VAR test %array{0,1,0,5,0}
Is there anyway I could get it to return 4? |
Then I suppose instead of returning 4, you'd want it to really return the index of 3 with the value of 5?
Ah, you know what. We have misunderstood each other. The first element of an array is at 0 (zero), not 1.
Now I understand your question Unfortunately, there is no "built-in" way of doing this. |
|
_________________ Carabas |
|
|
|
TonDiening GURU
Joined: 26 Jul 2001 Posts: 1958 Location: Canada
|
Posted: Sun Aug 14, 2005 3:20 am |
If you can use lists instead of arrays you can use the %max function.
|
|
|
|
|
|