binary-search-npm
A simple JavaScript utility function for performing binary search on an array. This function automatically sorts the array and returns the index of the target element if found, otherwise returns -1
.
📦 Installation
npm install binary-search-npm
🔧 Usage
const binarySearch = require('binary-search-npm');
const arr = [10, 5, 3, 8, 2];
const target = 8;
const result = binarySearch(arr, target);
console.log(result); // Output: 3