Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- };
Add Comment
Please, Sign In to add comment