Skip to content

Instantly share code, notes, and snippets.

  • Save anonymous/9837b4472966ca8e4ce0 to your computer and use it in GitHub Desktop.
Save anonymous/9837b4472966ca8e4ce0 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/elliotfriend 's solution for Bonfire: Where do I belong
// Bonfire: Where do I belong
// Author: @elliotfriend
// 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%20var%20newArray%20%3D%20arr.concat(num)%3B%0A%20%20return%20newArray.sort(function(a%2C%20b)%20%7B%0A%20%20%20%20return%20a%20-%20b%3B%0A%20%20%7D).indexOf(num)%3B%0A%7D%0A%0Awhere(%5B40%2C%2060%5D%2C%2050)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function where(arr, num) {
// Find my place in this sorted array.
var newArray = arr.concat(num);
return newArray.sort(function(a, b) {
return a - b;
}).indexOf(num);
}
where([40, 60], 50);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment