This file contains 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: Factorialize a Number | |
// Author: @mtroiani | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-factorialize-a-number | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function factorialize(num) { | |
var i = 1 | |
var product = 1 | |
while (i <= num) { | |
product = product * i; |
This file contains 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: Reverse a String | |
// Author: @mtroiani | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-reverse-a-string | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function reverseString(str) { | |
str = str.split('').reverse().join(''); | |
return str; | |
} |
This file contains 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: @mtroiani | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function palindrome(str) { | |
str = str.toLowerCase().replace(/[^\w]|_/g, ""); | |
var reversedStr = str.split("").reverse().join(""); | |
if (str === reversedStr) | |
return true; |
This file contains 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: @mtroiani | |
// 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 arrayOfStrings = str.split(" "); | |
var maxLength = 0; | |
for (var i=0; i < arrayOfStrings.length; i++) { | |
if (arrayOfStrings[i].length > maxLength) { |
This file contains 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: @mtroiani | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function titleCase(str) { | |
str = str.toLowerCase(''); | |
var capStr = str.charAt(0).toUpperCase(''); | |
for (var i = 1; i < str.length; i ++) { | |
if (str.charAt(i - 1) === " ") { |
This file contains 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: @mtroiani | |
// 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 bigArr = []; | |
for (var i = 0; i < arr.length; i ++) { | |
var largest = 0; | |
for (var n = 0; n < arr[i].length; n ++) { |
This file contains 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: @mtroiani | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function end(str, target) { | |
return str.substr(-target.length) === target; | |
} |
This file contains 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: @mtroiani | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-repeat-a-string-repeat-a-string | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function repeat(str, num) { | |
var result = ""; | |
if (num < 1) { | |
return ""; | |
} |
This file contains 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: @mtroiani | |
// 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 (num <= 3) { | |
return str.slice(0,num) + "..."; | |
} | |
else if (num >= str.length) { |
This file contains 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: @mtroiani | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-chunky-monkey | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function chunk(arr, size) { | |
var chunkedArr = []; | |
var n = 0; | |
for (var i = 0; i < arr.length; i += size) { | |
chunkedArr.push(arr.slice(i, i + size)); |
OlderNewer