Skip to content

Instantly share code, notes, and snippets.

@jgresalfi jgresalfi/sortAndAdd.js
Last active Sep 23, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.