Created
January 13, 2018 01:51
-
-
Save OneCent01/c7df3de81b1783e6e8e8c19c02a8d256 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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