What, exactly, is better code? Is it optimized for readability and understandability, or for performance?
In my opinion, writing your code in a clear and concise way should be step one, and only change the code for more performance if it is necessary. With the binary search function in Javascript, there are so many things going on that this would be nowhere near the top of things to optimize (except maybe in very exceptional cases).
If things work slow, it's a good skill to know how to optimize for performance โ but it is at least as important to know which parts take the most time and prioritizing what to work on first. And my guess is that in most cases, the binary search isn't what will take the most time.
Striving to become a master Go/Cloud developer; Father ๐จโ๐งโ๐ฆ; ๐ค/((Full Stack Web|Unity3D) + Developer)/g; Science supporter ๐ฉโ๐ฌ; https://coder.today
What, exactly, is better code? Is it optimized for readability and understandability, or for performance?
In this case is none of them, like I said in my first comment, it is a non-standard implementation (recursive, while most of the examples I could find are iterative), and less performant.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
What, exactly, is better code? Is it optimized for readability and understandability, or for performance?
In my opinion, writing your code in a clear and concise way should be step one, and only change the code for more performance if it is necessary. With the binary search function in Javascript, there are so many things going on that this would be nowhere near the top of things to optimize (except maybe in very exceptional cases).
If things work slow, it's a good skill to know how to optimize for performance โ but it is at least as important to know which parts take the most time and prioritizing what to work on first. And my guess is that in most cases, the binary search isn't what will take the most time.
In this case is none of them, like I said in my first comment, it is a non-standard implementation (recursive, while most of the examples I could find are iterative), and less performant.