Skip to content

Instantly share code, notes, and snippets.

View joePichardo's full-sized avatar

Joe Pichardo joePichardo

  • Phoenix, Arizona
View GitHub Profile
@joePichardo
joePichardo / bonfire-truncate-a-string.js
Created December 10, 2015 04:28
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a "..." ending. Note that the three dots at the end add to the string length. If the num is less than or equal to 3, then the length of the three dots is not added to the string length.
// Bonfire: Truncate a string
// Author: @joepichardo
// Challenge: http://www.freecodecamp.com/challenges/bonfire-truncate-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function truncate(str, num) {
// Clear out that junk in your trunk
var truncString = "";
@joePichardo
joePichardo / bonfire-repeat-a-string-repeat-a-string.js
Created December 10, 2015 03:58
Repeat a given string (first argument) n times (second argument). Return an empty string if n is a negative number.
// Bonfire: Repeat a string repeat a string
// Author: @joepichardo
// 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) {
// repeat after me
//creates an empty string to return
//if num is less than 0
@joePichardo
joePichardo / bonfire-confirm-the-ending.js
Created December 10, 2015 03:49
Check if a string (first argument) ends with the given target string (second argument).
// Bonfire: Confirm the Ending
// Author: @joepichardo
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function end(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
//variables used for substr(start, length)
var start = str.length-target.length;
@joePichardo
joePichardo / bonfire-return-largest-numbers-in-arrays.js
Created December 10, 2015 01:37
Return an array consisting of the largest number from each provided sub-array.
// Bonfire: Return Largest Numbers in Arrays
// Author: @joepichardo
// 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) {
// You can do this!
//empty array to place new numbers in
var largestArray = [];
var largestNumber = 0;
@joePichardo
joePichardo / bonfire-title-case-a-sentence.js
Created December 10, 2015 01:07
Capitalized first letter of each word, the rest are lower case.
// Bonfire: Title Case a Sentence
// Author: @joepichardo
// 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();
//make array for each word
var stringArray = str.split(" ");
for(var i = 0; i < stringArray.length; i++){
@joePichardo
joePichardo / bonfire-find-the-longest-word-in-a-string.js
Created December 10, 2015 00:23
Find the Longest Word in a String
// Bonfire: Find the Longest Word in a String
// Author: @joepichardo
// 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) {
//split string str into array for each space in the sentence
//console.log helps us validate and visualize this.
var strArray = str.split(" ");
console.log(strArray);
@joePichardo
joePichardo / bonfire-check-for-palindromes.js
Created December 9, 2015 17:53
Check for Palindromes
// Bonfire: Check for Palindromes
// Author: @joepichardo
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function palindrome(str) {
// Good luck!
str = str.toLowerCase();
//replaces spaces, non-alphanumberic, and underscores to no space
str = str.replace(/ |_|([^\w]*)/gi,"");
@joePichardo
joePichardo / bonfire-factorialize-a-number.js
Last active December 9, 2015 16:44
Factorialize a Number
// Bonfire: Factorialize a Number
// Author: @joepichardo
// Challenge: http://www.freecodecamp.com/challenges/bonfire-factorialize-a-number
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function factorialize(num) {
if(num === 0){
return 1;
}
@joePichardo
joePichardo / bonfire-reverse-a-string.js
Last active December 9, 2015 16:42
Reverse a String
// Bonfire: Reverse a String
// Author: @joepichardo
// Challenge: http://www.freecodecamp.com/challenges/bonfire-reverse-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function reverseString(str) {
var myArray = str.split(""); //splits each letter
myArray.reverse();
str = myArray.join("");//joins each letter w/o commas in b/w
return str;