{"id":1239,"date":"2025-10-02T20:20:33","date_gmt":"2025-10-02T19:20:33","guid":{"rendered":"https:\/\/monkey.ploogie.co.uk\/?page_id=1239"},"modified":"2026-01-09T15:19:41","modified_gmt":"2026-01-09T15:19:41","slug":"mwnci-bsearch-function","status":"publish","type":"page","link":"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-bsearch-function\/","title":{"rendered":"Mwnci bsearch() Function"},"content":{"rendered":"<h2><span id=\"Syntax\" class=\"mw-headline\">Syntax<\/span><\/h2>\n<p>bsearch(<i><b>array<\/b><\/i>, <i><b>string<\/b><\/i>)<\/p>\n<h2><span id=\"Description\" class=\"mw-headline\">Description<\/span><\/h2>\n<p>The <i>bsearch()<\/i> 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.<\/p>\n<h2><span id=\"Example\" class=\"mw-headline\">Example<\/span><\/h2>\n<pre>include(\"main\")\r\na=[1, 2, 3, 4, 5]\r\nb=[\"bob\", \"fred\", \"jim\", \"norbert\"]\r\nc=[1.1, 2.2, 9,4] \r\nprintln(bsearch(a, 3))\r\nprintln(bsearch(b, \"jim\"))\r\nprintln(bsearch(c, 1.1))\r\nprintln(bsearch(a, 7))\r\n\r\n\r\n2\r\n2\r\n-1\r\n-1\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-bsearch-function\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Mwnci bsearch() Function&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1239","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=1239"}],"version-history":[{"count":9,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1239\/revisions"}],"predecessor-version":[{"id":1286,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1239\/revisions\/1286"}],"wp:attachment":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=1239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}