Skip to content

Instantly share code, notes, and snippets.

  • Save sawant/eacc2a8b54278f4fd834 to your computer and use it in GitHub Desktop.
Save sawant/eacc2a8b54278f4fd834 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/sawant 's solution for Bonfire: Where do I belong
// Bonfire: Where do I belong
// Author: @sawant
// Challenge: http://www.freecodecamp.com/challenges/bonfire-where-do-i-belong?solution=function%20where(arr%2C%20num)%20%7B%0A%20%20%2F%2F%20Find%20my%20place%20in%20this%20sorted%20array.%0A%20%20arr.push(num)%3B%0A%20%20return%20arr.sort(function(a%2C%20b)%20%7Breturn%20a%20%3E%20b%3B%7D).indexOf(num)%3B%0A%7D%0A%0A%2F%2Fwhere(%5B40%2C%2060%5D%2C%2050)%3B%0Awhere(%5B5%2C%203%2C%2020%2C%203%5D%2C%205)%3B
// 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(a, b) {return a > b;}).indexOf(num);
}
//where([40, 60], 50);
where([5, 3, 20, 3], 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment