Skip to content

Instantly share code, notes, and snippets.

View slim-hmidi's full-sized avatar

Slim Hmidi slim-hmidi

  • Berlin
View GitHub Profile
const readline = require('readline');
const { binarySearch } = require('./binarySearch');
// create an interface
const rl = readline.createInterface({
input: process.stdin, // readable Stream: stdin
});
let T;
module.exports.binarySearch = (array, element) => {
// verify if the array is not null and contains elements
if (!array || !array.length) {
return -1;
}
let start = 0;
let end = array.length - 1;
while (start < end) {