{"size": 601, "ext": "js", "max_stars_repo_path": "binary.search.js", "max_stars_repo_name": "Olufemiobafunmiso/algorithms", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "binary.search.js", "max_issues_repo_name": "Olufemiobafunmiso/algorithms", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "binary.search.js", "max_forks_repo_name": "Olufemiobafunmiso/algorithms", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.1153846154, "max_line_length": 69, "alphanum_fraction": 0.5058236273}
//================BINARY SEARCH O(log n) complexity ===============//
const binarySearch = (arr,target)=>{

    // Sort array
  let array = arr.sort((a,b)=>{
    return a-b
  })
  
    let begin = 0;
    let end = array.length-1 //Last index
    while (begin <= end){
      let mid_index = Math.floor((begin+end)/2);
      let guess = array[mid_index]
      if(target === guess){
        return mid_index
      }
      if(guess > target){
       end = mid_index-1 //Move left
      }else{
        begin = mid_index+1 //Move right
      }
    }
    return -1;
  }
  
  binarySearch([1, 6, 3, 2, 5], 90)