Skip to content

Instantly share code, notes, and snippets.

@OneCent01
Created January 13, 2018 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OneCent01/c7df3de81b1783e6e8e8c19c02a8d256 to your computer and use it in GitHub Desktop.
Save OneCent01/c7df3de81b1783e6e8e8c19c02a8d256 to your computer and use it in GitHub Desktop.
var sortedIndex = function (array, value) {
var low = 0,
high = array.length;
while (low < high) {
var mid = (low + high) >>> 1;
if (array[mid] < value) low = mid + 1;
else high = mid;
}
return low;
};
var sortedInsert = function(arr, el) {
arr.splice(sortedIndex(arr, el), 0, el);
return arr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment