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 restaraunt = { | |
orders : [], | |
order : function(order) { | |
this.orders.push(order); | |
}, | |
total : function(orders) { | |
orders = orders || this.orders; | |
return orders.reduce(function(total, order) { | |
return total + order.cost; | |
}, 0); |
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 stillContainsArray(arr) { | |
return arr.some(item => item instanceof Array); | |
} | |
function concat(arr) { | |
return arr.reduce((a,b) => a.concat(b), []); | |
} | |
function flatten(arr) { | |
while(stillContainsArray(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 lotto() { | |
function getBalls() { | |
var random = getRandom(1,59); | |
if(!balls.includes(random)) { | |
balls.push(random); | |
} | |
if(balls.length < 6) { | |
return getBalls(); | |
} | |
else { |
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
/* | |
Constructor vs Literal | |
*/ | |
// Array | |
var foo = new Array(); // constructor | |
var bar = []; // literal | |
// difference? | |
// constructor - inconsistent API |
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
// a function returning `something` in javascript is a useful tool | |
function foo() { | |
return "foo"; | |
} | |
// create a reference | |
var bar; | |
// if we assign `bar` to `foo` | |
bar = foo; |
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
// write a script that checks for broken image links on a page | |
// and hides them if they're not available | |
// feel free to come up with a method that doesn't ever reveal broken links to the user |
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
// take a bunch of football results from this object | |
// and return an array of results summaries including teams competing, score and scorers | |
var results = { | |
"02-01-2016" : { | |
results : [{ | |
teamA : { | |
name : "Manchester United", | |
goals : 2, | |
scorers : ["Rooney", "Martial"], |
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
/* | |
The function should convert the name into a number (somehow?) and multiply it by the current time. | |
The answer should be divided by 2. If that number is even, the person is cool, otherwise they're not :( | |
*/ | |
function arrayOfStringsToNum(arr) { | |
var alphabet = strToArray("abcdefghijklmnopqrstuvwxyz"); | |
return arr.reduce((a, b) => a += alphabet.indexOf(b.toLowerCase()), 0); |
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
/* | |
style: | |
.marker { | |
background-color: #5F5FFF; | |
width: 7px; | |
height: 7px; | |
border-radius: 50%; | |
position: absolute; | |
box-shadow: 2px 2px 5px rgba(0,0,0,0.5); | |
} |
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
// with three methods toBe, toBeExactly and toBeTypeof | |
function Assert(val) { | |
return { | |
toBe : function(expected) { | |
return val == expected; | |
}, | |
toBeExactly : function(expected) { | |
return val === expected; | |
}, | |
toBeTypeof : function(expected) { |