Skip to content

Commit

Permalink
feat: add binarySearch algorithm and update exports in index.ts; bump…
Browse files Browse the repository at this point in the history
… version in package.json
  • Loading branch information
gabriel-logan committed Nov 6, 2024
1 parent 80d7253 commit 4160a21
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dsacjs",
"version": "0.0.1-test",
"version": "0.0.2-test",
"description": "A high-performance JavaScript and TypeScript library offering a comprehensive set of efficient data structures. Simplify your algorithm implementation and data manipulation with optimized, easy-to-use tools.",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
Expand Down
20 changes: 20 additions & 0 deletions src/Algorithms/binarySearch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default function binarySearch(arr: number[], target: number): number {
let left = 0;
let right = arr.length - 1;

while (left <= right) {
const mid = Math.floor((left + right) / 2);

if (arr[mid] === target) {
return mid;
}

if (arr[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}

return -1;
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import binarySearch from "./Algorithms/binarySearch";
import DoublyLinkedList from "./dataStructures/DoublyLinkedList";
import Queue from "./dataStructures/Queue";
import SingleLinkedList from "./dataStructures/SingleLinkedList";
Expand All @@ -10,4 +11,5 @@ export {
Queue,
DoublyLinkedList as LinkedList,
Logger,
binarySearch,
};

0 comments on commit 4160a21

Please sign in to comment.