Skip to content

Instantly share code, notes, and snippets.

@clive-bunting
clive-bunting / bonfire-pairwise.js
Created December 8, 2015 20:43
Bonfire: Pairwise
// Bonfire: Pairwise
// Author: @clive-bunting
// Challenge: http://www.freecodecamp.com/challenges/bonfire-pairwise
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function pairwise(arr, arg) {
var used = [];
for (var i = 0; i < arr.length - 1; i++) {
if (used.indexOf(i) === -1) {
for (var j = i + 1; j < arr.length; j++) {
@clive-bunting
clive-bunting / bonfire-map-the-debris.js
Created December 8, 2015 20:39
Bonfire: Map the Debris
// Bonfire: Map the Debris
// Author: @clive-bunting
// Challenge: http://www.freecodecamp.com/challenges/bonfire-map-the-debris
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function orbitalPeriod(arr) {
var GM = 398600.4418;
var earthRadius = 6367.4447;
var results = [];
for(var i = 0; i < arr.length; i++) {
@clive-bunting
clive-bunting / bonfire-steamroller.js
Created December 5, 2015 15:32
Bonfire: Steamroller
// Bonfire: Steamroller
// Author: @clive-bunting
// Challenge: http://www.freecodecamp.com/challenges/bonfire-steamroller#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function steamroller(arr) {
var flat = [];
for (var i =0; i < arr.length; i++) {
if (Array.isArray(arr[i])) {
var flattened = steamroller(arr[i]);
@clive-bunting
clive-bunting / bonfire-everything-be-true.js
Created December 5, 2015 15:19
Bonfire: Everything Be True
// Bonfire: Everything Be True
// Author: @clive-bunting
// Challenge: http://www.freecodecamp.com/challenges/bonfire-everything-be-true#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function every(collection, pre) {
for (var i = 0; i < collection.length; i++) {
if (!collection[i][pre]) {
return false;
}
@clive-bunting
clive-bunting / bonfire-sum-all-primes.js
Created December 5, 2015 15:07
Bonfire: Sum All Primes
// Bonfire: Sum All Primes
// Author: @clive-bunting
// 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 = [];
for (var trial = 2; trial <= num; trial++) {
var isPrime = true;
for (var prime = 0; prime < primes.length; prime++) {
@clive-bunting
clive-bunting / bonfire-make-a-person.js
Created December 5, 2015 10:19
Bonfire: Make a Person
// Bonfire: Make a Person
// Author: @clive-bunting
// Challenge: http://www.freecodecamp.com/challenges/bonfire-make-a-person#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
var Person = function(firstAndLast) {
var firstName = firstAndLast.split(' ')[0];
var lastName = firstAndLast.split(' ')[1];
this.getFirstName = function() {
@clive-bunting
clive-bunting / bonfire-smallest-common-multiple.js
Created December 5, 2015 10:13
Bonfire: Smallest Common Multiple
// Bonfire: Smallest Common Multiple
// Author: @clive-bunting
// Challenge: http://www.freecodecamp.com/challenges/bonfire-smallest-common-multiple#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function smallestCommons(arr) {
var lbound = Math.min(arr[0], arr[1]);
var ubound = Math.max(arr[0], arr[1]);
var multiple = 0;
var multipleFound = false;
@clive-bunting
clive-bunting / bonfire-arguments-optional.js
Created December 4, 2015 21:13
Bonfire: Arguments Optional
// Bonfire: Arguments Optional
// Author: @clive-bunting
// Challenge: http://www.freecodecamp.com/challenges/bonfire-arguments-optional
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function add() {
if (typeof arguments[0] !== "number") {
return undefined;
}
@clive-bunting
clive-bunting / bonfire-binary-agents.js
Created December 4, 2015 21:08
Bonfire: Binary Agents
// Bonfire: Binary Agents
// Author: @clive-bunting
// Challenge: http://www.freecodecamp.com/challenges/bonfire-binary-agents
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function binaryAgent(str) {
var numbers = str.split(' ');
var output = '';
for (var i = 0; i < numbers.length; i++) {
var charCode = parseInt(numbers[i], 2);
@clive-bunting
clive-bunting / bonfire-drop-it.js
Created December 4, 2015 21:01
Bonfire: Drop it
// Bonfire: Drop it
// Author: @clive-bunting
// Challenge: http://www.freecodecamp.com/challenges/bonfire-drop-it
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function drop(arr, func) {
if (arr.length === 0 || func(arr[0])) {
return arr;
}
arr.shift();