Skip to content

Instantly share code, notes, and snippets.

View dbess1's full-sized avatar

Delante Lee Bess dbess1

  • Boston; NY; SF; Chicago
View GitHub Profile
// Object initialiser or literal
{ [ nameValuePair1[, nameValuePair2[, ...nameValuePairN] ] ] }
// Called as a constructor
new Object([value])
// Bonfire: Falsy Bouncer
// Author: @dbess1
// Challenge: http://www.freecodecamp.com/challenges/bonfire-falsy-bouncer
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function bouncer(arr) {
//Based on the MDN document this will Boolean function will include all falsy values
//I can just filter all of them with filter function!
return arr.filter(Boolean);
// Bonfire: Mutations
// Author: @dbess1
// Challenge: http://www.freecodecamp.com/challenges/bonfire-mutations
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function mutation(arr) {
var stringToArray1 = arr[0].toLowerCase().split(""); //h,e,l,l,o
var stringToArray2 = arr[1].toLowerCase().split(""); //h,e,y
// Bonfire: Truncate a string
// Author: @dbess1
// Challenge: http://www.freecodecamp.com/challenges/bonfire-truncate-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function truncate(str, num) {
if(str.length > num && num > 3){
return str.slice(0, num - 3) + "...";
}
// Bonfire: Slasher Flick
// Author: @dbess1
// Challenge: http://www.freecodecamp.com/challenges/bonfire-slasher-flick
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function slasher(arr, howMany) {
if(howMany < arr.length){
var chop = arr.splice(0, howMany);
return arr;
// Bonfire: Confirm the Ending
// Author: @dbess1
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function end(str, target) {
//I used a conditional to check if str (string) has the requested ending letter or word
//The target is the requested letter or word which is being called below
if(str.substr(-target.length) == target){
return true;
// Bonfire: Return Largest Numbers in Arrays
// Author: @dbess1
// Challenge: http://www.freecodecamp.com/challenges/bonfire-return-largest-numbers-in-arrays
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function largestOfFour(arr) {
var numbers = [];
for(var i = 0; i < arr.length; i++){ //for iterating through the large array
var biggestNumber = 0;
for(var j = 0; j < arr[i].length; j++){ //for iterating through the sub-arrays
// Bonfire: Title Case a Sentence
// Author: @dbess1
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function titleCase(str) {
return str.toLowerCase().replace(/^[a-z]|\s[a-z]/g, function(i){ return i.toUpperCase(); } );
}
titleCase("I'm a little tea pot");
// Bonfire: Find the Longest Word in a String
// Author: @dbess1
// Challenge: http://www.freecodecamp.com/challenges/bonfire-find-the-longest-word-in-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function findLongestWord(str) {
var allWords = str.split(" ");
var biggestWords = 0;
// Bonfire: Check for Palindromes
// Author: @dbess1
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function palindrome(str) {
var word = str.toLowerCase().replace(/[\W_]/g, "");
var reversedWord = word.split("").reverse().join("");
return word === reversedWord;
}