Created
August 14, 2017 00:32
-
-
Save bytao7mao/1784313ba8aba948325a5ec661c6f55d to your computer and use it in GitHub Desktop.
JS push and sort
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
function getIndexToIns(arr, num) { | |
arr.push(num); // first we add a number in the array | |
arr.sort(function(a, b) { // then we sort the array in ascending order | |
return a-b; | |
}); | |
return arr.indexOf(num); //then we return the index of the num added to the array | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment