Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
How to find/print return value of a function?

Doing a basic binary search problem, but how do you know if it actually works if you cant see the number that's being returned??

function binarySearch(arr, val) {
    let start = 0;
    let end = arr.length - 1;
  
    while (start <= end) {
      let mid = Math.floor((start + end) / 2);
  
      if (arr[mid] === val) {
        return mid;
      }
  
      if (val < arr[mid]) {
        end = mid - 1;
      } else {
        start = mid + 1;
      }
    }
    return -1;
}

let arr = [1,9,3,4,5,7,2];

binarySearch(arr, 9);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The binary search only works if the array is sort. Use arr.sort()

about 4 years ago · Juan Pablo Isaza Report

0

If you want to debug or just see the print , you can try debugging option in any of the code editor or just add print before return statements with time , to realize what is returned

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!