This file contains 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
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; | |
This file contains 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
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)); |
This file contains 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
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++) { |
This file contains 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
//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)){ |
This file contains 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
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]); |
This file contains 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
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(); |
This file contains 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
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; |
This file contains 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
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; |
This file contains 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
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; | |
} |
This file contains 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
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); |
OlderNewer