Skip to content

Instantly share code, notes, and snippets.

View mtroiani's full-sized avatar

Mary Troiani mtroiani

  • Software Engineer
  • Seattle, WA
View GitHub Profile
@mtroiani
mtroiani / gist:893bb2b42a32e9f36069
Created December 11, 2015 18:42
http://www.freecodecamp.com/mtroiani 's solution for Bonfire: Factorialize a Number
// 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;
@mtroiani
mtroiani / gist:1a8e9b9254c82ee56e2b
Created December 11, 2015 18:50
http://www.freecodecamp.com/mtroiani 's solution for Bonfire: Reverse a String
// 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;
}
@mtroiani
mtroiani / gist:81ad68a1f19027086ed2
Created December 11, 2015 20:42
http://www.freecodecamp.com/mtroiani 's solution for Bonfire: Check for Palindromes
// 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;
@mtroiani
mtroiani / gist:55ec5bf1c1cf83ffc814
Created December 11, 2015 22:13
http://www.freecodecamp.com/mtroiani 's solution for Bonfire: Find the Longest Word in a String
// 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) {
@mtroiani
mtroiani / gist:c2fd178d4c40920650e8
Created December 11, 2015 23:17
http://www.freecodecamp.com/mtroiani 's solution for Bonfire: Title Case a Sentence
// 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) === " ") {
@mtroiani
mtroiani / gist:7656f50288befc965165
Created December 12, 2015 00:38
http://www.freecodecamp.com/mtroiani 's solution for Bonfire: Return Largest Numbers in Arrays
// 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 ++) {
@mtroiani
mtroiani / gist:1579d7ef75b1e42741c8
Created December 12, 2015 01:03
http://www.freecodecamp.com/mtroiani 's solution for Bonfire: Confirm the Ending
// 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;
}
@mtroiani
mtroiani / gist:f721499b40ac1c8cd921
Created December 12, 2015 01:24
http://www.freecodecamp.com/mtroiani 's solution for Bonfire: Repeat a string Repeat a string
// 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 "";
}
@mtroiani
mtroiani / gist:b221df5e64ded9c33cc0
Created December 12, 2015 01:34
http://www.freecodecamp.com/mtroiani 's solution for Bonfire: Truncate a String
// 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) {
@mtroiani
mtroiani / gist:028ca90e075e8025e1af
Created December 12, 2015 02:11
http://www.freecodecamp.com/mtroiani 's solution for Bonfire: Chunky Monkey
// 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));