Skip to content

Instantly share code, notes, and snippets.

Created December 4, 2015 11:07
Show Gist options
  • Save anonymous/a93b08ffe3322abf278a to your computer and use it in GitHub Desktop.
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
// 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