Skip to content

Instantly share code, notes, and snippets.

@jgresalfi
Last active September 23, 2016 15:45
Show Gist options
  • Save jgresalfi/06d062aa7ee00f4422641940e7692947 to your computer and use it in GitHub Desktop.
Save jgresalfi/06d062aa7ee00f4422641940e7692947 to your computer and use it in GitHub Desktop.
Return lowest possible index position of second argument after it is added to the first arg's array and sorted...
function getIndexToIns(arr, num) {
let numArr = arguments[0],
addNum = arguments[1];
numArr.push(addNum);
numArr.sort(function(a, b) {
return a - b;
});
return numArr.indexOf(addNum);
}
getIndexToIns([40, 60], 70);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment