Mwnci bsearch() Function

Syntax

bsearch(array, string)

Description

The bsearch() function makes a binary search on data within a sorted array and returns the index in the array of the first entry found. The data must be sorted in ascending order and be of a single type. I.e the array must be made up of a single set of integers, floats, or strings. If an entry is not found, or the array is not sorted, then -1 is returned.

Example

include("main")
a=[1, 2, 3, 4, 5]
b=["bob", "fred", "jim", "norbert"]
c=[1.1, 2.2, 9,4]
println(bsearch(a, 3))
println(bsearch(b, "jim"))
println(bsearch(c, 1.1))
println(bsearch(a, 7))


2
2
-1
-1