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: @say2neeraj | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-mutations | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function mutation(arr) { | |
var str = arr[0].toLowerCase(); | |
var search = arr[1].toLowerCase(); | |
for (var i = 0; i < search.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: @say2neeraj | |
// 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%20return%20arr.slice(howMany)%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 | |
return arr.slice(howMany); | |
} |
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: @say2neeraj | |
// 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%20var%20j%3D0%3B%0A%20%20%0A%20%20var%20result%3D%5B%5D%3B%0A%20%20for(var%20i%3D0%3Bi%3Carr.length%3Bi%3Di%2Bsize)%0A%20%20%20%20%7B%0A%20%20%20%20%20var%20x%3Dsize%3B%0A%20%20%20%20%20%20var%20newArray%3D%5B%5D%3B%0A%20%20%20%20%20%20while(x%3E0%20%26%26j%3Carr.length)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20newArray.push(arr%5Bj%2B%2B%5D)%3B%0A%20%20%20%20%20%20%20%20%20%20x--%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20result.push(newArray)%3B%0A%20%20%20%20%7D%0A%20%20return%20result%3B%0A%20%20%0A%7D%0A%0Achunk(%5B%22a%22%2C%20%22b%22%2C%20%22c%22%2C%20%22d%22%5D%2C%202)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function chunk(arr, size) { | |
// Break it up. | |
var j=0; | |
var result=[]; |
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: @say2neeraj | |
// 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%20if(str.length%3Enum)%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%0A%20%20%20%20%20%20%20if(num%3C%3D3)%20%0A%20%20%20%20%20%20%20%20%20%2F%2FTrim%20the%20text%0A%20%20%20%20%20%20%20%20%20return%20str.slice(0%2Cnum).concat(%22...%22)%3B%20%0A%20%20%20%20%20%20%20else%0A%20%20%20%20%20%20%20%20%20return%20str.slice(0%2Cnum-3).concat(%22...%22)%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20else%0A%20%20%20%20%20%20%20%20return%20str%3B%0A%7D%0A%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 | |
if(str.length>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: @say2neeraj | |
// 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%20%20var%20newString%20%3D%20%22%22%3B%0A%20%20%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20num%3B%20i%2B%2B)%20%7B%0A%20%20%20%20newString%20%2B%3D%20str%3B%0A%20%20%7D%0A%20%20%0A%20%20return%20newString%3B%0A%7D%0Arepeat(%22abc%22%2C%203)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function repeat(str, num) { | |
// repeat after me | |
var newString = ""; | |
for (var i = 0; i < num; 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: @say2neeraj | |
// 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(str!%3D%3Dnull)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20return%20(str.substring(str.length-target.length)%20%3D%3D%3D%20target)%3B%0A%20%20%20%20%7D%0A%20%20else%0A%20%20%20%20%7B%0A%20%20%20%20%20%20return%20false%3B%0A%20%20%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(str!==null) |
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
function largestOfFour(arr) { | |
// You can do this! | |
var newArr = []; | |
// Iterate main array | |
for(var i=0; i<arr.length; ++i) { | |
var largest = 0; | |
// Iterate subarrays | |
for(var j=0; j<arr[i].length; ++j) | |
// Compare the largest value among sub-arrays | |
if(arr[i][j] > largest) |
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: @say2neeraj | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence?solution=function%20titleCase(str)%20%7B%0A%20%20%20%2F%2FSplit%20the%20words%20by%20space.%0A%20%20%20var%20words%20%3D%20str.split(%22%20%22)%3B%0A%20%20%2F%2FCreate%20and%20store%20in%20array.%0A%20%20%20var%20arr%20%3D%20Array()%3B%0A%20%20%20for%20(var%20i%20in%20words)%0A%20%20%20%7B%0A%20%20%20%20%20%2F%2FConvert%20all%20alphabets%20to%20lowercase.%0A%20%20%20%20%20%20temp%20%3D%20words%5Bi%5D.toLowerCase()%3B%0A%20%20%20%20%20%2F%2FConvert%20first%20alphabet%20to%20Capital%20and%20concatenate%20rest%20of%20the%20string.%0A%20%20%20%20%20%20temp%20%3D%20temp.charAt(0).toUpperCase()%20%2B%20temp.substring(1)%3B%0A%20%20%20%20%20%2F%2FStore%20in%20array.%0A%20%20%20%20%20%20arr.push(temp)%3B%0A%20%20%20%7D%0A%20%20%2F%2FFinally%20join%20all%20the%20splitted%20words%20to%20make%20final%20string.%0A%20%20%20return%20arr.join(%22%20%22)%3B%0A%7D%0A%0AtitleCase(%22I%27m% |
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: @say2neeraj | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-find-the-longest-word-in-a-string?solution=function%20findLongestWord(str)%20%7B%0A%20%20var%20longest%20%3D%200%3B%0A%20%20var%20string%20%3D%20str.split(%22%20%22)%3B%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20string.length%3B%20i%2B%2B)%7B%0A%20%20%20%20if(string%5Bi%5D.length%20%3E%20longest)%7B%0A%20%20%20%20%20%20%20longest%20%3D%20string%5Bi%5D.length%3B%0A%20%20%20%20%7D%0A%0A%20%20%7D%0A%20return%20longest%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 findLongestWord(str) { | |
var longest = 0; | |
var string = str.split(" "); | |
for (var i = 0; i < string.length; i++){ | |
if(string[i].length > longest){ |
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: @say2neeraj | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes?solution=function%20palindrome(str)%20%7B%0A%20%20%20%20%2F%2FRemove%20non-alphabets%20and%20whitespaces%0A%20%20%20%20str%20%3D%20str.toLowerCase().replace(%2F%5CW%7C_%2Fg%2C%22%22)%3B%0A%20%20%20%0A%20%20%20%20%2F%2F%20Good%20luck!%0A%20%20%0A%20%20%20%20%2F%2FFunction%20to%20reverse%20any%20string%0A%20%20%20%20function%20reverse(x)%7B%0A%20%20%20%20return%20x.split(%22%22).reverse().join(%22%22)%3B%0A%20%20%20%20%7D%0A%20%20%0A%20%20%20%20var%20str1%20%3D%20reverse(str)%3B%0A%20%20%20%20var%20str2%20%3D%20reverse(str1)%3B%0A%20%20%20%20if(str1%3D%3Dstr2)%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20return%20true%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20else%0A%20%20%20%20%7Breturn%20false%3B%0A%20%20%20%20%7D%20%20%0A%20%20%0A%20%7D%0A%0Apalindrome(%22eye%22)%3B | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function palindrome(str) { | |
//Remove non-al |
NewerOlder