Skip to content

Instantly share code, notes, and snippets.

View aldraco's full-sized avatar

Ashley Drake aldraco

View GitHub Profile
@aldraco
aldraco / countdown-feb.js
Created February 16, 2015 15:29
Reddit /dailyprogrammer challenge from Feb 09, 2015.
module.exports = function(input) {
//take input string and parse to a date object.
var targetDate = Date.parse(input);
//figure out the current date, in a date object
var todaysDate = Date.now();
//find the difference between the two dates
var difference = targetDate - todaysDate;
@aldraco
aldraco / gist:9f67eeec71fa81971b0e
Created February 21, 2015 17:56
Where Art Thou bonfire challenge from Free Code Camp - two versions
function where(collection, source) {
var arr = [];
var keyName = Object.keys(source)[0];
collection.forEach(function(person) {
if (person.hasOwnProperty(keyName) && (person[keyName] === source[keyName])) {
//console.log(person[keyName]);
arr.push(person);
}
});
console.log("1"+ JSON.stringify(arr));
@aldraco
aldraco / gist:25223627a0b9f224f94d
Created February 26, 2015 19:02
sum prime numbers bonfire Challenge
function sumPrimes(num) {
//create an array of prime numbers up to num
var primesArray = [];
function isPrime(number) {
//tests for prime
//var index = 2;
var sqrt = Math.sqrt(number);
for (var index=2; index <= sqrt; index++) {
@aldraco
aldraco / gist:d6932a417b87605ddc83
Created February 26, 2015 20:32
lowest common divisor - in progress
//Find the smallest number that is evenly divisble by all numbers in the provided range.
function smallestCommons(arr) {
var primeArr =[];
var compArr= [];
for(var i = arr[0]; i <= arr[1]; i++){
// call is prime function on each number and push prime one way and comp another
if(isPrime(i)){
@aldraco
aldraco / gist:7359b92f203a59900cc9
Created February 28, 2015 16:58
Pairwise bonfire FCC - very ugly solution
function pairwise(arr, arg) {
var indexRef = [];
var pushIndex;
// go through the arr
for (var i = 0; i < arr.length; i ++) {
// if that index is not already in indexRef, continue
if (indexRef.indexOf(i) < 0) {
// for that element, find its pair (arr.indexOf)
pushIndex = arr.indexOf(arg-arr[i]);
@aldraco
aldraco / gist:3c28733baa1e83bfbafb
Created February 28, 2015 17:56
symmetric diff bonfire (WIP)
function sym(arr) {
//get args
var args = Array.prototype.slice.call(arguments);
//symmetric difference is the union minus the intersection
//find the union with no duplicates
function findUnion (arr1, arr2) {
var union = (arr1.concat(arr2)).sort();
@aldraco
aldraco / gist:058d4837dfd1fbf5fcef
Last active August 29, 2015 14:16
make a person bonfire FCC (WIP) - TODO does not pass instance of Person test.
var Person = function(firstAndLast) {
//private variables
var name = firstAndLast;
var firstName = name.split(' ')[0];
var lastName = name.split(' ')[1];
//updated to pass the bonfire test
this.getFullName = function() {
return name;
@aldraco
aldraco / gist:5c6c944109ed37db171b
Last active August 29, 2015 14:16
cash register challenge
function drawer(price, payment, cid) {
var change = payment - price;
function findCID (cid) {
var total = 0;
cid.forEach(function(value, index) {
total += value[1];
});
return total;
@aldraco
aldraco / gist:1a849c294f1ff1151a93
Created March 1, 2015 18:03
Inventory Update WIP
function inventory(warehouse, shipment) {
// create a key list of items already in warehouse
function makeInvList(list) {
var IL = [];
list.forEach(function(item, index) {
IL.push(item[1]);
});
return IL;
}
function permAlone(str) {
str = str.split('');
// find total permutations, or (str.length!)
// subtract possible pair perms
// n = # of unique letters
// x = # of each repeated letter
// pair perms = n! * x!
var len = str.length;
var letters = uniqueLetters(str);