-
Notifications
You must be signed in to change notification settings - Fork 340
Bonfire Falsey Bouncer
Created by Rafase282
Github | FreeCodeCamp | CodePen | LinkedIn | Website | E-Mail
- Difficulty: 1/5
Remove all falsey values from an array.
Falsey values in javascript are false, null, 0, "", undefined, and NaN.
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
function bouncer(arr) {
// Don't show a false ID to this bouncer.
return arr;
}
bouncer([7, 'ate', '', false, 9]);
Falsey values in javascript are false, null, 0, "", undefined, and NaN. Everything else is basically truthy. So if we find any falsey we have to filter then out.
Filter() requires a callback function, you need to create it.
You will return a boolean of the argument from the callback function, use Boolean(arg)
If you figure out how to use filter and boolean then you are all set, if not then keep checking for the answer.
function bouncer(arr) {
function isTruthy(arg){
return Boolean(arg);
}
var filteredArray = arr.filter(isTruthy);
return filteredArray;
}
- Create a callback function that returns a boolean using the argument passed to it.
- use that call back function with filter to filter the array and return the filtered array.
Thanks for visiting, if you like this please feel free to star my repo, follow me or even contact me about contributing as it will be a lot of work and having help would be cool.
- HTML5 and CSS
- Responsive Design with Bootstrap
- Gear up for Success
- jQuery
- Basic JavaScript
- Object Oriented and Functional Programming
- Basic Algorithm Scripting
- Basic Front End Development Projects
- Intermediate Algorithm Scripting
- JSON APIs and Ajax
- Intermediate Front End Development Projects
- Claim Your Front End Development Certificate
- Upper Intermediate Algorithm Scripting
- Automated Testing and Debugging
- Advanced Algorithm Scripting
- AngularJS (Legacy Material)
- Git
- Node.js and Express.js
- MongoDB
- API Projects
- Dynamic Web Applications
- Claim Your Back End Development Certificate
- Greefield Nonprofit Project 1
- Greefield Nonprofit Project 2
- Legacy Nonprofit Project 1
- Legacy Nonprofit Project 2
- Claim your Full Stack Development Certification
- Whiteboard Coding Interview Training
- Critical Thinking Interview Training
- Mock Interview 1
- Mock Interview 2
- Mock Interview 3