Skip to content

Instantly share code, notes, and snippets.

View patrickcurl's full-sized avatar

Patrick Curl patrickcurl

View GitHub Profile
// Bonfire: Everything Be True
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-everything-be-true
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function every(collection, pre) {
// Is everyone being true?
var returnVal = true;
collection.forEach(function(x){
console.log(x.hasOwnProperty(pre));
// Bonfire: Binary Agents
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-binary-agents
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function binaryAgent(str) {
return String.fromCharCode(...str.split(" ").map(function(char){ return parseInt(char, 2); }));
}
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
// Bonfire: Steamroller
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-steamroller
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function steamroller(arr) {
// I'm a steamroller, baby
var newArr = [];
var flatten = function(x){
if(!Array.isArray(x)){
// Bonfire: Drop it
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-drop-it
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function drop(arr, func) {
// Drop them elements.
while(!func(arr[0])){
arr.shift();
}
// Bonfire: Finders Keepers
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-finders-keepers
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function find(arr, func) {
newArr = arr.filter(func);
return newArr[0];
}
// Bonfire: Smallest Common Multiple
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-smallest-common-multiple
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function smallestCommons(arr) {
range = toRange(arr);
return range.reduce(function(a, b) {
return lcm(a, b);
});
// Bonfire: Sum All Primes
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sum-all-primes
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function sumPrimes(num) {
if(num === 1){
return 0;
}
// Bonfire: Sum All Odd Fibonacci Numbers
// Author: @patrickcurl
// 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 a = 0, b = 1, c = 1, sum = 0;
var arr = [0];
// Bonfire: Spinal Tap Case
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-spinal-tap-case
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function spinalCase(str) {
return str.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/\s+|_+/g, '-').toLowerCase();
}
// Bonfire: Convert HTML Entities
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-convert-html-entities
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function convert(str) {
// :)
var arr = str.split("");
arr.forEach(function(x,y){
if(x === "&"){