finds an item in an array matching a predicate function, and returns its index