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: Finders Keepers | |
// Author: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-finders-keepers | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function find(arr, func) { | |
var num = 0; | |
num = arr.filter(function(val) { | |
return func(val); |
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: Smallest Common Multiple | |
// Author: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-smallest-common-multiple | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function smallestCommons(arr) { | |
arr.sort(); | |
var nums = [], multiple = arr[0]; | |
for (var i = arr[0]; i <= arr[1]; i++) { | |
nums.push(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: Sum All Primes | |
// Author: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sum-all-primes | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function sumPrimes(num) { | |
var primes = [2]; | |
function isPrime(n) { | |
for (var i = 2; i < n; 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: Sum All Odd Fibonacci Numbers | |
// Author: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sum-all-odd-fibonacci-numbers | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function sumFibs(num) { | |
var fibs = getFibs(num), | |
oddFibs = []; | |
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: Spinal Tap Case | |
// Author: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-spinal-tap-case | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function spinalCase(str) { | |
// "It's such a fine line between stupid, and clever." | |
// --David St. Hubbins | |
str = str.replace(/([a-z])([A-Z])/g, '$1 $2') | |
.toLowerCase().replace(/\s/g, '-') |
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: Convert HTML Entities | |
// Author: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-convert-html-entities | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function convert(str) { | |
// :) | |
return str.replace(/&/g, '&') | |
.replace(/</g, '<') | |
.replace(/>/g, '>') |
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: Sorted Union | |
// Author: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sorted-union | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function unite(arr1, arr2, arr3) { | |
var args = Array.prototype.slice.call(arguments); | |
arr1 = args.reduce(function(old, cur) { | |
var obj = {}, diff; | |
for (var i = 0; i < old.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: DNA Pairing | |
// Author: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-dna-pairing | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function pair(str) { | |
var pairing = { | |
"A": "T", | |
"T": "A", | |
"C": "G", |
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: Pig Latin | |
// Author: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-pig-latin | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function translate(str) { | |
var vowelReg = /^[aeiou]/i, | |
index = []; | |
if ((vowelReg).test(str)) { |
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: Search and Replace | |
// Author: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-search-and-replace | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function myReplace(str, before, after) { | |
if ((/^[A-Z]/).test(before)) after = after.charAt(0).toUpperCase() + after.slice(1); | |
str = str.replace(new RegExp(before, 'gi'), after); | |
return str; | |
} |