JSFiddle - React, Tailwind, and code Playground

by Sudheer Nunna

JavaScript

doSearch = function(array, targetValue) {  
 
 var minIndex = 0;    var maxIndex = array.length - 1; 
 var currentIndex;    
 var currentElement;     
 while (minIndex <= maxIndex) {    
 currentIndex = (minIndex + maxIndex) / 2 | 0;  
 currentElement = array[currentIndex];    
 if (currentElement < targetValue) {  
 minIndex = currentIndex + 1;     
 } else if (currentElement > targetValue) { 
 maxIndex = currentIndex - 1;     
 } else {           
 return currentIndex;  
 }    }  
 return -1;  
 };