Created
December 4, 2015 03:53
-
-
Save justincorrigible/6489cf2c571e4449b2b1 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/hallaathrad 's solution for Bonfire: Where do I belong
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
fire-where-do-i-belong.js | |
// Bonfire: Where do I belong | |
// Author: @hallaathrad | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-where-do-i-belong | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function where(arr, num) { | |
// Find my place in this sorted array. | |
arr.push(num); | |
return arr.sort(function(x,y){return x<y?-1:x>y?1:0;}).indexOf(num); | |
} | |
where([40, 60], 50); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Return the lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted.