Created
December 7, 2015 01:21
-
-
Save anonymous/73be27ec6999bee71668 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/fcc0208647c '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
// Bonfire: Where do I belong | |
// Author: @fcc0208647c | |
// 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) { | |
myarr = arr.sort(function(a,b) {return a - b;}); | |
console.log(myarr); | |
minval = Math.min.apply(Math, myarr); | |
maxval = Math.max.apply(Math, myarr); | |
if (num <= minval){return 0;} | |
if (num >= maxval){return arr.length;} | |
for (i=0; i < arr.length; i++) { | |
if (num > arr[i] && num <= arr[i+1]) { | |
return i+1; | |
} | |
} | |
} | |
where([40, 60], 50); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment