package_atif
Version:
A simple module to test the publishing of npm packages and also to test the binary search algorithm.
31 lines (23 loc) • 648 B
JavaScript
const welcomeUser = (username = "") => {
console.log(`Welcome ${username}`);
}
// welcomeUser("John Doe");
// module.exports = {welcomeUser};
// binarySearch.js
function binarySearch(arr, target) {
let low = 0;
let high = arr.length - 1;
while (low <= high) {
const mid = Math.floor((low + high) / 2);
const guess = arr[mid];
if (guess === target) {
return mid;
} else if (guess < target) {
low = mid + 1;
} else {
high = mid - 1;
}
}
return -1; // Element not found
}
module.exports = {binarySearch, welcomeUser};