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: 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: 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: 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: 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: 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: 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: 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: Find the Longest Word in a String | |
// Author: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-find-the-longest-word-in-a-string?solution=function%20findLongestWord(str)%20%7B%0A%20%20%2F%2Fs%5Blit%20the%20string%0A%20%20var%20strArray%20%3D%20str.split(%22%20%22)%3B%0A%20%20%0A%20%20%2F%2Ffind%20the%20longest%20word%20in%20the%20array%0A%20%20strArray.sort(function%20(a%2Cb)%20%7B%0A%20%20%20%20if(a.length%20%3C%20b.length)%7B%2F%2Fif%20a%20is%20shorter%20move%20b%20down%0A%20%20%20%20%20%20return%201%3B%0A%20%20%20%20%7Delse%20if(a.length%20%3E%20b.length)%7B%2F%2Fif%20b%20shorer%20move%20a%20down%0A%20%20%20%20%20%20return%20-1%3B%0A%20%20%20%20%7Delse%7B%0A%20%20%20%20%20%20return%200%3B%0A%20%20%20%20%7D%0A%20%20%7D)%3B%0A%20%20console.log(strArray)%3B%0A%20%20return%20strArray%5B0%5D.length%3B%0A%7D%0A%0AfindLongestWord(%22The%20quick%20brown%20fox%20jumped%20over%20the%20lazy%20dog%22)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function findLongestWor |
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: Check for Palindromes | |
// Author: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes?solution=function%20palindrome(str)%20%7B%0A%20%20%2F%2Fto%20lowercase%0A%20%20str%20%3D%20str.toLowerCase()%3B%0A%20%20%2F%2Fremove%20punctuations%0A%20%20str%20%3D%20str.replace(%2F%5B.%3F!%2C%5Cs~%7B%7D()%3A%3B%5C-_%5C%2F%5C%5C%5D%2Fgi%2C%27%27)%3B%0A%20%20%2F%2Freverse%0A%20%20var%20reverse%20%3D%20str.split(%27%27).reverse().join(%27%27)%3B%0A%20%20%0A%20%20console.log(str%2B%22%20and%20%22%2Breverse)%3B%0A%20%20%0A%20%20%2F%2Fif%20doesn%27t%20work%20backwards%0A%20%20if(str%20!%3D%3D%20reverse)%7B%0A%20%20%20%20return%20false%3B%0A%20%20%7D%0A%20%20return%20true%3B%0A%7D%0A%0A%0A%0Apalindrome(%220_0%20(%3A%20%2F-%5C%20%3A)%200-0%22)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function palindrome(str) { | |
//to lowercase | |
str = str.toLowerCase(); | |
//remove punctuations | |
str = str.replace(/[.?!,\s~{}():;\-_\/\\]/gi,''); |