Title: Binary Search in JavaScript - Runnable Code Snippet
Open Graph Title: Binary Search in JavaScript - Runnable Code Snippet
X Title: Binary Search in JavaScript - Runnable Code Snippet
Description: Find the index of an element in a sorted array using binary search with O(log n) time complexity. Runnable JavaScript snippet with live execution.
Open Graph Description: Find the index of an element in a sorted array using binary search with O(log n) time complexity. Runnable JavaScript snippet with live execution.
X Description: Find the index of an element in a sorted array using binary search with O(log n) time complexity. Runnable JavaScript snippet with live execution.
Keywords:
Opengraph URL: https://tempercode.dev/snippets/binary-search-javascript
Domain: tempercode.dev
{"@context":"https://schema.org","@type":"SoftwareSourceCode","name":"Binary Search","description":"Find the index of an element in a sorted array using binary search with O(log n) time complexity.","programmingLanguage":"JavaScript","text":"let lo = 0, hi = arr.length - 1, result = -1;\nwhile (lo <= hi) {\n const mid = Math.floor((lo + hi) / 2);\n if (arr[mid] === target) { result = mid; break; }\n else if (arr[mid] < target) lo = mid + 1;\n else hi = mid - 1;\n}\nreturn result;"}
| theme-color | #0c0d12 |
| color-scheme | dark |
| author | Temper |
| creator | Temper |
| publisher | Temper |
| og:image | https://tempercode.dev/og-image.png |
| og:type | article |
| twitter:card | summary_large_image |
| twitter:image | https://tempercode.dev/og-image.png |
Links:
Viewport: width=device-width, initial-scale=1