function findPlace(x, arr) {
const len = arr.length;
if (!len || x > arr[0]) return 1;
if (x <= arr[len - 1]) return len + 1;
const pivot = midPivot(arr.length);
// const pivot = randomPivot(arr.length);
if (arr[pivot] < x) {
return findPlace(x, arr.slice(0, pivot));
} else {
return pivot + findPlace(x, arr.slice(pivot));
}
}
function midPivot(len) {
return Math.round(len / 2);
}
function randomPivot(len) {
return Math.floor(Math.random() * (len - 1)) + 1;
}
Created
May 25, 2018 17:25
-
-
Save KolosovAO/4066a343b1c5fcc5ba6d8c9e72cf064d to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment