@vikas9479/binary-search-vikas 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +12 -0
- package/package.json +16 -0
package/index.js
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
const binarySearch = (arr, tar)=>{
|
2
|
+
let left =0;
|
3
|
+
let right = arr.length-1;
|
4
|
+
while(left<=right){
|
5
|
+
let mid = Math.floor((left+right)/2);
|
6
|
+
if(arr[mid]==tar) return mid;
|
7
|
+
else if(arr[mid]<tar) return mid+1;
|
8
|
+
else return mid-1;
|
9
|
+
}
|
10
|
+
return -1;
|
11
|
+
}
|
12
|
+
module.exports = binarySearch;
|
package/package.json
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"name": "@vikas9479/binary-search-vikas",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "A simple binary search algorithm implementation",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"test": "echo \"No tests specified\" && exit 0"
|
8
|
+
},
|
9
|
+
"keywords": [
|
10
|
+
"binary search",
|
11
|
+
"algorithm",
|
12
|
+
"search"
|
13
|
+
],
|
14
|
+
"author": "Your Name",
|
15
|
+
"license": "MIT"
|
16
|
+
}
|