Finding position of a value in an array
Rumbu
rumbu at rumbu.ro
Sat Feb 6 15:47:05 UTC 2021
On Sunday, 29 December 2019 at 08:26:58 UTC, Daren Scot Wilson
wrote:
> Reading documentation... Array, Algorithms, ... maybe I've been
> up too late... how does one obtain the index of, say, 55 in an
> array like this
>
> int[] a = [77,66,55,44];
>
> I want to do something like:
>
> int i = a.find_value_returning_its_index(55);
> assert(i==2)
>
> I'm sure it's obvious but I'm not seeing it right now.
Just reactivating this post to tell you that I lost 15 minutes of
my life searching for a basic way to obtain the position of an
element in an array; Out of frustration, I ended to write my own
indexOf function. Any library on Earth has such function and it's
not named countUntil, nor giveMeTheDamnPositionOfXInThatArray.
It seems that D is specialised in finding needles in haystacks,
not finding elements in arrays.
https://issues.dlang.org/show_bug.cgi?id=21615
More information about the Digitalmars-d-learn
mailing list