Finding position of a value in an array

bachmeier no at spam.net
Tue Dec 31 11:25:01 UTC 2019


On Tuesday, 31 December 2019 at 04:38:53 UTC, Daren Scot Wilson 
wrote:
> On Monday, 30 December 2019 at 23:15:48 UTC, JN wrote:
>> On Sunday, 29 December 2019 at 08:31:13 UTC, mipri wrote:
>>>
>>> int i = a.countUntil!(v => v == 55);
>>> assert(i == 2);
>>
>> I also had to ask because I couldn't find it. In other 
>> languages it's named "index()", "indexOf()" or "find()". D is 
>> the only language I know which uses the "countUntil" scheme. 
>> And even so it's not obvious from the name if it's the index 
>> of the element or number of preceding elements.
>
>
> I had first tried myarray.index(myvalue) because I coulda sworn 
> I wrote exactly that syntax a only a few days ago.  But I've 
> been hopping between languages, some D, some Crystal, some C++, 
> some Javascript, and with only two cerebral hemispheres, maybe 
> I got confused. So, D doesn't have index()?  Is it called 
> find()?  Something else?  It was hard to find the right stuff 
> in the documentation.

You may have used indexOf, which works with strings. Why not 
anything else? No idea, as it really should work with other 
arguments.


More information about the Digitalmars-d-learn mailing list