Guest User

Untitled

a guest
Jan 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. var sortedIndex = function (array, value) {
  2. var low = 0,
  3. high = array.length;
  4. while (low < high) {
  5. var mid = (low + high) >>> 1;
  6. if (array[mid] < value) low = mid + 1;
  7. else high = mid;
  8. }
  9. return low;
  10. };
  11.  
  12. var sortedInsert = function(arr, el) {
  13. arr.splice(sortedIndex(arr, el), 0, el);
  14. return arr;
  15. };
Add Comment
Please, Sign In to add comment