Skip to content

Instantly share code, notes, and snippets.

View nhaancs's full-sized avatar

Nhan Nguyen (Nathan) nhaancs

View GitHub Profile
// Bonfire: Where do I belong
// Author: @nhancs
// 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.sort(function(a%2C%20b)%7B%0A%20%20%20%20return%20a-b%3B%0A%20%20%7D)%3B%0A%20%20var%20arr_length%20%3D%20arr.length%3B%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20arr_length%3B%20i%2B%2B)%7B%0A%20%20%20%20if%20(num%20%3E%3D%20arr%5Bi%5D%20%26%26%20num%20%3C%3D%20arr%5Bi%2B1%5D)%20return%20(i%2B1)%3B%0A%20%20%7D%0A%20%20return%20arr_length%3B%0A%7D%0A%0Awhere(%5B40%2C%2060%5D%2C%2030)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function where(arr, num) {
// Find my place in this sorted array.
arr.sort(function(a, b){
return a-b;
});
// Bonfire: Falsy Bouncer
// Author: @nhancs
// Challenge: http://www.freecodecamp.com/challenges/bonfire-falsy-bouncer?solution=function%20bouncer(arr)%20%7B%0A%20%20%2F%2F%20Don%27t%20show%20a%20false%20ID%20to%20this%20bouncer.%0A%20%20var%20new_arr%20%3D%20arr.filter(function(a)%7B%0A%20%20%20%20if%20(a%3D%3D%3D%27%27%20%7C%7C%20a%3D%3D%3Dnull%20%7C%7C%20a%3D%3D%3D0%20%7C%7C%20a%3D%3D%3Dundefined%20%7C%7C%20a%3D%3D%3DisNaN)%20return%20false%3B%0A%20%20%20%20return%20a%3B%0A%20%20%7D)%3B%0A%20%20return%20new_arr%3B%0A%7D%0A%0Abouncer(%5B7%2C%20%22ate%22%2C%20%22%22%2C%20false%2C%209%5D)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var new_arr = arr.filter(function(a){
if (a==='' || a===null || a===0 || a===undefined || a===isNaN) return false;
return a;