Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. const findElCircular = function findElCircular(array, x, low = 0, high = array.length - 1) {
  2. const mid = Math.floor((high + low) / 2);
  3.  
  4. // base case
  5. if (array[mid] === x) return mid;
  6.  
  7. if (array[mid] <= array[high]) {
  8. if (x > array[mid] && x <= array[high]) {
  9. low = mid + 1;
  10. } else {
  11. high = mid - 1;
  12. }
  13. } else if (array[mid] >= array[low]) {
  14. if (x >= array[low] && x < array[mid]) {
  15. high = mid - 1;
  16. } else {
  17. low = mid + 1;
  18. }
  19. }
  20.  
  21. return findElCircular(array, x, low, high);
  22. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement