Skip to content

Instantly share code, notes, and snippets.

View SabeBarker's full-sized avatar
👾

Sabe Barker SabeBarker

👾
View GitHub Profile
@SabeBarker
SabeBarker / bonfire-reverse-a-string.js
Last active November 11, 2015 05:23
Bonfire: Reverse a String
// Bonfire: Reverse a String
// Author: @phoenixlaef
// Challenge: http://www.freecodecamp.com/challenges/bonfire-reverse-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function reverseString(str) {
return str.split('').reverse().join('');
}
reverseString("hello");
@SabeBarker
SabeBarker / bonfire-factorialize-a-number.js
Last active November 12, 2015 17:20
Bonfire: Factorialize a Number
// Bonfire: Factorialize a Number
// Author: @phoenixlaef
// Challenge: http://www.freecodecamp.com/challenges/bonfire-factorialize-a-number
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function factorialize(num) {
return num === 0 ? 1 : num * factorialize(num - 1);
}
factorialize(5);
@SabeBarker
SabeBarker / bonfire-check-for-palindromes.js
Last active September 25, 2016 07:00
Bonfire: Check for Palindromes
// Bonfire: Bonfire: Check for Palindromes
// Author: @sabebarker
// 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.replace(/\W|_/g, "").toLowerCase();
return str === str.split("").reverse().join("");
}
palindrome("eye");
@SabeBarker
SabeBarker / bonfire-find-the-longest-word-in-a-string.js
Last active September 25, 2016 07:10
Bonfire: Find the Longest Word in a String
// Bonfire: Find the Longest Word in a String
// Author: @sabebarker
// 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) {
str = str.split(" ");
var numArray = [];
for (var i = 0; i < str.length; i++) {
numArray.push(str[i].length);
}
@SabeBarker
SabeBarker / bonfire-title-case-a-sentence.js
Last active September 25, 2016 07:08
Bonfire: Title Case a Sentence
// Bonfire: Title Case a Sentence
// Author: @sabebarker
// 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().split(' ');
var newArray = [];
for(var i = 0; i < str.length; i++){
newArray.push(str[i].charAt(0).toUpperCase() + str[i].slice(1));
}
@SabeBarker
SabeBarker / bonfire-return-largest-numbers-in-arrays.js
Last active September 25, 2016 07:07
Bonfire: Return Largest Numbers in Arrays
// Bonfire: Return Largest Numbers in Arrays
// Author: @sabebarker
// 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 maxNumArray = [];
for (var i = 0; i < arr.length; i++){
var maxNum = Math.max.apply(null, arr[i]);
maxNumArray.push(maxNum);
}
@SabeBarker
SabeBarker / bonfire-confirm-the-ending.js
Last active September 25, 2016 07:06
Bonfire: Confirm the Ending
// Bonfire: Confirm the Ending
// Author: @sabebarker
// 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 target === str.substr(str.length - target.length);
}
end("Bastian", "n");
@SabeBarker
SabeBarker / bonfire-repeat-a-string-repeat-a-string.js
Last active September 25, 2016 07:06
Bonfire: Repeat a string repeat a string
// Bonfire: Repeat a string repeat a string
// Author: @sabebarker
// 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) {
if (num < 0) {
return "";
} else if (num === 0){
return str;
} else {
@SabeBarker
SabeBarker / bonfire-truncate-a-string.js
Last active September 25, 2016 07:05
Bonfire: Truncate a string
// Bonfire: Truncate a string
// Author: @sabebarker
// 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 (str.length > num){
return str.slice(0, num - 3) + '...';
} else {
@SabeBarker
SabeBarker / bonfire-chunky-monkey.js
Last active September 25, 2016 07:04
Bonfire: Chunky Monkey
// Bonfire: Chunky Monkey
// Author: @sabebarker
// Challenge: http://www.freecodecamp.com/challenges/bonfire-chunky-monkey
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function chunk(arr, size) {
newArray = [];
while(arr.length) {
newArray.push(arr.splice(0, size));
}
return newArray;