mori icon indicating copy to clipboard operation
mori copied to clipboard

How do you get the index of a given string in a sequence of strings?

Open binarykitchen opened this issue 9 years ago • 3 comments

This seems to be missing ... thanks for any hints

binarykitchen avatar Mar 24 '16 03:03 binarykitchen

There is an undocumented function keepIndexed that you can use in this fashion:

const kept = mori.keepIndexed((idx, string) => string === referenceString ? idx : null, strings)
const matchingIndex = mori.first(kept)

hallettj avatar Mar 26 '16 22:03 hallettj

thanks @hallettj but why is it undocumented?

binarykitchen avatar Apr 04 '16 21:04 binarykitchen

I don't know why keepIndexed is not documented. I happened to get a pretty good look at that and other unadvertised functions while assembling type definitions for Mori.

hallettj avatar Apr 05 '16 05:04 hallettj