Index of Array List

Index of Array List

fsl88
Contributor Contributor
3,387 Views
2 Replies
Message 1 of 3

Index of Array List

fsl88
Contributor
Contributor
Hello everyone. Need help on getting the index number of the minimum value, and the index number of the 2nd minimum value.
Pictured below gets the actual value of the minimum and 2nd minimum value respectively.
This is in a (for loop).
fsl88_1-1637002406516.png

 

 

Thank you.
0 Likes
Accepted solutions (1)
3,388 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant

Hi,

It is very difficult (if not impossible) to answer you without knowing what arrayLength, skip1, take1 are. You should provide some example of these collections.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 3

_gile
Consultant
Consultant
Accepted solution

Here's an extension method which sorts the elements in a collection, and returns the element index numbers.

public static IEnumerable<int> SortI<T>(this IEnumerable<T> source) where T : IComparable
{
    int i = 0;
    return source
        .Select(x => new { Value = x, Index = i++ })
        .OrderBy(x => x.Value)
        .Select(x => x.Index);
}

 

 

 

 

> var array = new[] { 1, 3, 5, 2, 4, 6};
> array.SortI().ToArray()
int[6] { 0, 3, 1, 4, 2, 5 }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes