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: Title Case a Sentence | |
// Author: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence?solution=function%20titleCase(str)%20%7B%0A%20%20%2F%2Fsplit%20it%20up%20to%20play%20with%0A%20%20var%20strArray%20%3D%20str.split(%22%20%22)%3B%0A%20%20%0A%20%20%2F%2Falter%20values%0A%20%20return%20strArray.map(function(val)%7B%0A%20%20%20%20%2F%2Fput%20UpperCase%20in%20the%20first%20position%0A%20%20%20%20console.log(val.charAt(0).toUpperCase()%20%2B%20val.slice(1).toLowerCase())%3B%0A%20%20%20%20return%20val.charAt(0).toUpperCase()%20%2B%20val.slice(1).toLowerCase()%3B%0A%20%20%7D).join(%22%20%22)%3B%0A%7D%0A%0AtitleCase(%22I%27m%20a%20little%20tea%20pot%22)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function titleCase(str) { | |
//split it up to play with | |
var strArray = str.split(" "); | |
//alter values |
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: Return Largest Numbers in Arrays | |
// Author: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-return-largest-numbers-in-arrays?solution=function%20largestOfFour(arr)%20%7B%0A%20%20%2F%2Freturned%20array%0A%20%20var%20rArr%20%3D%20%5B%5D%3B%0A%20%20%2F%2Fnormal%20for%20loop%0A%20%20for(var%20i%3D0%3B%20i%3Carr.length%3B%20i%2B%2B)%7B%0A%20%20%20%20arr%5Bi%5D.sort(function(a%2Cb)%7B%0A%20%20%20%20%20%20return%20b-a%3B%0A%20%20%20%20%7D)%3B%0A%20%20%20%20%0A%20%20%20%20rArr.push(arr%5Bi%5D%5B0%5D)%3B%0A%20%20%7D%0A%20%20return%20rArr%3B%0A%7D%0A%0AlargestOfFour(%5B%5B4%2C%205%2C%201%2C%203%5D%2C%20%5B13%2C%2027%2C%2018%2C%2026%5D%2C%20%5B32%2C%2035%2C%2037%2C%2039%5D%2C%20%5B1000%2C%201001%2C%20857%2C%201%5D%5D)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function largestOfFour(arr) { | |
//returned array | |
var rArr = []; | |
//normal for loop | |
for(var i=0; i<arr.length; i++){ |
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: Confirm the Ending | |
// Author: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending?solution=function%20end(str%2C%20target)%20%7B%0A%20%20%2F%2F%20%22Never%20give%20up%20and%20good%20luck%20will%20find%20you.%22%0A%20%20%2F%2F%20--%20Falcor%0A%20%20%0A%20%20if(target%20%3D%3D%3D%20str.substr(str.length-target.length%2Ctarget.length))%7B%0A%20%20%20%20%20return%20true%3B%20%20%20%0A%20%20%7Delse%7B%0A%20%20%20%20%20return%20false%3B%0A%20%20%7D%0A%7D%0A%0Aend(%22Bastian%22%2C%20%22n%22)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function end(str, target) { | |
// "Never give up and good luck will find you." | |
// -- Falcor | |
if(target === str.substr(str.length-target.length,target.length)){ |
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: Repeat a string repeat a string | |
// Author: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-repeat-a-string-repeat-a-string?solution=function%20repeat(str%2C%20num)%20%7B%0A%20%20%2F%2F%20repeat%20after%20me%0A%20%20if(num%20%3E%3D%200)%7B%0A%20%20%20return%20str.repeat(num)%3B%20%0A%20%20%7Delse%7B%0A%20%20%20%20return%20%22%22%3B%0A%20%20%7D%0A%7D%0A%0Arepeat(%22abc%22%2C%203)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function repeat(str, num) { | |
// repeat after me | |
if(num >= 0){ | |
return str.repeat(num); | |
}else{ |
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: Truncate a string | |
// Author: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-truncate-a-string?solution=function%20truncate(str%2C%20num)%20%7B%0A%20%20%2F%2F%20Clear%20out%20that%20junk%20in%20your%20trunk%0A%20%20%0A%20%20var%20rString%20%3D%20str.slice(0%2Cnum)%3B%0A%20%20%0A%20%20if(rString.length%20%3C%3D%203)%7B%0A%20%20%20%20return%20rString%20%2B%20%22...%22%3B%0A%20%20%7Delse%20if(str.length%20%3C%3D%20num)%7B%0A%20%20%20%20return%20str%3B%0A%20%20%7D%0A%20%20%0A%20%20return%20rString.slice(0%2C-3)%20%2B%20%22...%22%3B%0A%0A%7D%0A%0Atruncate(%22A-tisket%20a-tasket%20A%20green%20and%20yellow%20basket%22%2C%2011)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function truncate(str, num) { | |
// Clear out that junk in your trunk | |
var rString = str.slice(0,num); | |
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: Chunky Monkey | |
// Author: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-chunky-monkey?solution=function%20chunk(arr%2C%20size)%20%7B%0A%20%20%2F%2F%20Break%20it%20up.%0A%20%20%2F%2Fcreate%20return%20array%0A%20%20var%20rArray%20%3D%20%5B%5D%3B%0A%20%20%0A%20%20var%20tempArray%20%3D%20%5B%5D%3B%0A%20%20%2F%2Floop%20through%0A%20%20for(var%20i%20%3D%200%3B%20i%20%3C%3D%20arr.length%20%3B%20i%2B%2B)%7B%0A%20%20%20%20console.log(i)%3B%0A%20%20%20%20if(tempArray.length%20%3D%3D%20size%20%7C%7C%20i%20%3D%3D%20arr.length)%7B%0A%20%20%20%20%20%20%2F%2Fif%20full%0A%20%20%20%20%20%20rArray.push(tempArray)%3B%0A%20%20%20%20%20%20%2F%2Fempty%20temp%0A%20%20%20%20%20%20tempArray%20%3D%20%5B%5D%3B%0A%20%20%20%20%20%20%0A%20%20%20%20%20%20%20tempArray.push(arr%5Bi%5D)%3B%0A%20%20%20%20%7Delse%7B%0A%20%20%20%20%20%20tempArray.push(arr%5Bi%5D)%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20return%20rArray%3B%0A%7D%0A%0Achunk(%5B0%2C%201%2C%202%2C%203%2C%204%2C%205%5D%2C%204)%3B%0A | |
// Learn to Code a |
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: Slasher Flick | |
// Author: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-slasher-flick?solution=function%20slasher(arr%2C%20howMany)%20%7B%0A%20%20%2F%2F%20it%20doesn%27t%20always%20pay%20to%20be%20first%0A%20%20%20arr.splice(0%2ChowMany)%3B%0A%20%20return%20arr%3B%0A%7D%0A%0Aslasher(%5B1%2C%202%2C%203%5D%2C%202)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function slasher(arr, howMany) { | |
// it doesn't always pay to be first | |
arr.splice(0,howMany); | |
return arr; | |
} |
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: Mutations | |
// Author: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-mutations?solution=function%20mutation(arr)%20%7B%0A%20%20var%20state%3B%0A%20%20var%20string1%20%3D%20arr%5B0%5D.toLowerCase()%3B%0A%20%20var%20string2%20%3D%20arr%5B1%5D.toLowerCase()%3B%0A%20%20for(var%20i%20%3D%200%3B%20i%20%3C%20arr%5B1%5D.length%3B%20i%2B%2B)%7B%0A%20%20%20%20var%20value%20%3D%20string1.indexOf(string2.charAt(i))%3B%0A%20%20%20%20if(value%20%3D%3D%3D%20-1)%7B%0A%20%20%20%20%20%20return%20false%3B%0A%20%20%20%20%7Delse%7B%0A%20%20%20%20%20%20state%20%3D%20true%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20%0A%20%20return%20state%3B%0A%7D%0A%0Amutation(%5B%22hello%22%2C%20%22hey%22%5D)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function mutation(arr) { | |
var state; | |
var string1 = arr[0].toLowerCase(); | |
var string2 = arr[1].toLowerCase(); | |
for(var i = 0; i < arr[1].length; i++){ |
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: Falsy Bouncer | |
// Author: @v3rse | |
// 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%20return%20arr.filter(function(val)%7B%0A%20%20%20%20return%20%20Boolean(val)%3B%0A%20%20%7D)%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. | |
return arr.filter(function(val){ | |
return Boolean(val); | |
}); |
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: Seek and Destroy | |
// Author: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-seek-and-destroy?solution=var%20currArg%3B%0A%2F%2Fclean%20code%0Afunction%20cleaner(val)%7B%0A%20%20%20%20%20%20return%20val%20!%3D%20currArg%3B%20%2F%2Fafter%20zero%0A%7D%0A%0Afunction%20destroyer(arr)%20%7B%0A%20%20%2F%2F%20Remove%20all%20the%20values%0A%20%20%2F%2Fget%20extra%20arguments%0A%20%20for(var%20i%20%3D%201%3B%20i%3Carguments.length%3B%20i%2B%2B)%7B%0A%20%20%20%20%20console.log(currArg%2B%22%3Abefore%20%22%2Barr)%3B%0A%20%20%20%20currArg%20%3D%20arguments%5Bi%5D%3B%0A%20%20%20%20arr%20%3D%20arr.filter(cleaner)%3B%0A%20%20%20%20console.log(currArg%2B%22%3Aafter%20%22%2Barr)%3B%0A%20%20%7D%0A%20%20return%20arr%3B%0A%7D%0A%0Adestroyer(%5B1%2C%202%2C%203%2C%201%2C%202%2C%203%5D%2C%202%2C%203)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
var currArg; | |
//clean code | |
function cleaner(val){ | |
return val != currArg; //after zero | |
} |