Le samedi 07 novembre 2015 à 06:37 -0800, Michele Zaffalon a écrit : > What is the best way of telling whether an element `x` is present in > a sorted list `a`? > > Using `searchsortedlist`, I also need to check that the element is > present in the list. This is what I do > > function isinsortedlist(a, x) > n = searchsortedfirst(a, x) > n <= length(a) && a[n] == x > end > > Shouldn't `searchsortedlist` return also a bool to tell whether the > element is already in the list? Just use searchsorted(), which (as the docs say) "Returns an empty range located at the insertion point if a does not contain values equal to x".
Regards > Thank you, > michele
