Here're some tips on how to divide numbers in javascript without using the "/" operator. This is a very efficacy method. Which means that it has ju...
For further actions, you may consider blocking this person and/or reporting abuse
Alternatively you can do a binary search for the solution in range 0 to dividend in log(n) time
Thank you for your comment! Yes, using binary search for division can indeed provide a more efficient solution, especially for large dividends. It's a great way to optimize the algorithm and reduce computation time. I appreciate you highlighting this approach!
Alternatively you can do a binary search for the solution in range 0 to dividend
Absolutely, it can be used in the** while loop**.
There are many methods that can be used to in accomplish this same results.
Binary
while (left <= right) {
let mid = Math.floor((left + right) / 2);
if (mid * divisor <= dividend) {
quotient = mid;
left = mid + 1;
} else {
right = mid - 1;
}
}
you can enable syntax highlighting through:
triple backtick javascript
code
triple backtick
Thanks for letting me know Buddy!
You could also use logarithms
Thank you for your comment! It's a great way to optimize the algorithm and reduce computation time. I appreciate you highlighting this approach!
? I never mentioned binary search
Yes, you'll need some code to handle negative numbers, but this highlights the main approach
I didn't use the
/
operator :)I like it! I wonder if there is a way to speed this up by wrapping the negative number handling into the math 🤔
That's a great idea! Handling negative numbers within the mathematical calculations can streamline the code and potentially improve its efficiency. One way to achieve this is by leveraging the absolute values of the dividend and divisor during the binary search process, and then adjusting the sign of the quotient accordingly. This approach avoids the need for separate handling of negative numbers.