Skip to content

Instantly share code, notes, and snippets.

View patrickcurl's full-sized avatar

Patrick Curl patrickcurl

View GitHub Profile
// Bonfire: Sorted Union
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sorted-union
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function unite() {
var myArray = [];
for (var i = 0; i < arguments.length; i++) {
for (var j = 0; j < arguments[i].length; j++) {
if (myArray.indexOf(arguments[i][j]) < 0) {
// Bonfire: Boo who
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-boo-who
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function boo(bool) {
// What is the new fad diet for ghost developers? The Boolean.
if(typeof bool === "boolean"){
return true;
}
// Bonfire: Missing letters
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-missing-letters
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function fearNotLetter(str) {
for(var i=0;i<str.length;i++){
var letter = str.charCodeAt(i);
if(letter !== str.charCodeAt(0) + i)
{
// Bonfire: DNA Pairing
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-dna-pairing
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function pair(str) {
var dna = str.split("");
var pairs = [];
dna.forEach(function(x){
if(x === "G"){ pairs.push(["G","C"]);}
// Bonfire: Pig Latin
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-pig-latin
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function translate(str) {
var first = str.charAt(0);
var cluster = str.charAt(0) + str.charAt(1);
startsWithVowel = false;
// Bonfire: Search and Replace
// Author: @patrickcurl
// 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) {
arr = str.split(" ");
arr.forEach(function(x,y){
if(x == before){
// Bonfire: Where art thou
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-where-art-thou
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function where(collection, source) {
// "What's in a name? that which we call a rose
var sourceKeys = Object.keys(source);
return collection.filter(function (o) {
// Bonfire: Roman Numeral Converter
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-roman-numeral-converter
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function convert(num) {
if(num < 1){ return "";}
if(num >= 1000){return "M" + convert(num-1000);}
if(num >= 900){ return "CM" + convert(num-900);}
if(num >= 500){return "D" + convert(num-500);}
// Bonfire: Sum All Numbers in a Range
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sum-all-numbers-in-a-range
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function sumAll(arr) {
var newArr = [];
for(var i=Math.min(...arr); i<=Math.max(...arr); i++){
newArr.push(i);
// Bonfire: Diff Two Arrays
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-diff-two-arrays
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function diff(arr1, arr2) {
var newArr = [];
arr1.forEach(function(a){
if(arr2.indexOf(a) == -1){
newArr.push(a);