-
-
Save anonymous/c0d404768dbdbaf9eb9e to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/emaaljn 's solution for Bonfire: Where do I belong
This file contains hidden or 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: @emaaljn | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-where-do-i-belong?solution=function%20where(arr%2C%20num)%20%7B%0A%20%0A%20%20%2F%2F%20sort%20array.%0A%20%20arr.sort(function(a%2C%20b)%7B%0A%20%20%20%20return%20a%20-%20b%3B%0A%20%20%7D)%3B%0A%20%20%0A%20%20var%20counter%20%3D%200%3B%0A%20%20for(var%20i%20%3D%200%3B%20i%20%3C%20arr.length%3B%20i%2B%2B)%7B%0A%20%20%20%20if(arr%5Bi%5D%20%3C%20num)%7B%0A%20%20%20%20%20%20counter%20%2B%3D%201%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20%0A%20%20return%20counter%3B%0A%7D%0A%0Awhere(%5B10%2C%2020%2C%2030%2C%2040%2C%2050%5D%2C%2030)%3B | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function where(arr, num) { | |
// sort array. | |
arr.sort(function(a, b){ | |
return a - b; | |
}); | |
var counter = 0; | |
for(var i = 0; i < arr.length; i++){ | |
if(arr[i] < num){ | |
counter += 1; | |
} | |
} | |
return counter; | |
} | |
where([10, 20, 30, 40, 50], 30); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment