Last active
June 5, 2017 15:33
-
-
Save rodpoblete/8adf614d4d06523d246f3b205f834f2c to your computer and use it in GitHub Desktop.
Obtener el index de un elemento insertado y ordenado en un array - FCC[256]
This file contains hidden or 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); // agrego el numero al array | |
var newArr = arr.sort(function (a, b) {return a - b; }); // con el metodo .sort() ordeno el array de forma ASC | |
return newArr.indexOf(num); // obtengo el index del elemento num | |
} | |
getIndexToIns([2, 5, 10], 15); // obtengo 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment