Created
December 4, 2015 11:07
-
-
Save anonymous/a93b08ffe3322abf278a to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/narshe1412 '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: @narshe1412 | |
// 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. | |
var sortedArray = arr.sort(function(a,b){ | |
return a-b; | |
}); | |
var result = 0; | |
for (var i=0; i<sortedArray.length; i++){ | |
if (num <= sortedArray[i]) {return i;} | |
} | |
return i; //if value is outside the array | |
} | |
where([40, 60], 50); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment