swannodette / mori

ClojureScript's persistent data structures and supporting API from the comfort of vanilla JavaScript
http://swannodette.github.io/mori
3.39k stars 148 forks source link

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

Open binarykitchen opened 8 years ago

binarykitchen commented 8 years ago

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

hallettj commented 8 years ago

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)
binarykitchen commented 8 years ago

thanks @hallettj but why is it undocumented?

hallettj commented 8 years ago

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.