Skip to content

Instantly share code, notes, and snippets.

  • Save anonymous/e493076139c6d8b8699c to your computer and use it in GitHub Desktop.
Save anonymous/e493076139c6d8b8699c to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/dbagia 's solution for Bonfire: Where do I belong
// Bonfire: Where do I belong
// Author: @dbagia
// 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%20arr.sort(function(a%2Cb)%7B%0A%20%20%20%20return%20a%20-%20b%3B%0A%20%20%7D)%3B%0A%0A%20%20return%20arr.indexOf(num)%3B%0A%7D%0A%0Awhere(%5B2%2C%205%2C%2010%5D%2C%2015)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function where(arr, num) {
// Find my place in this sorted array.
arr.push(num);
arr.sort(function(a,b){
return a - b;
});
return arr.indexOf(num);
}
where([2, 5, 10], 15);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment