Skip to content

Instantly share code, notes, and snippets.

View MikeDigitize's full-sized avatar
👋
Howdy

Mike Chadwick MikeDigitize

👋
Howdy
View GitHub Profile
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);
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)) {
@MikeDigitize
MikeDigitize / Write a lottery ball generator
Last active November 28, 2016 23:50
Some coding challenges for the AO front end team who are learning JavaScript
function lotto() {
function getBalls() {
var random = getRandom(1,59);
if(!balls.includes(random)) {
balls.push(random);
}
if(balls.length < 6) {
return getBalls();
}
else {
@MikeDigitize
MikeDigitize / Literals vs Constructors
Last active January 21, 2016 21:59
Helpers for beginners to JavaScript at AO.com
/*
Constructor vs Literal
*/
// Array
var foo = new Array(); // constructor
var bar = []; // literal
// difference?
// constructor - inconsistent API
@MikeDigitize
MikeDigitize / returns are useful!
Last active January 6, 2016 22:08
Helpers for beginners to JavaScript at AO.com
// 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;
@MikeDigitize
MikeDigitize / Broken image link checker
Created January 3, 2016 20:13
Some coding challenges for the AO front end team who are learning JavaScript
@MikeDigitize
MikeDigitize / Format a bunch of football results
Last active January 26, 2016 07:33
Some coding challenges for the AO front end team who are learning JavaScript
// 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"],
@MikeDigitize
MikeDigitize / Write a function that takes a name and decides how lucky that person is
Created January 3, 2016 20:07
Some coding challenges for the AO front end team who are learning JavaScript
/*
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);
@MikeDigitize
MikeDigitize / Write a script to draws a simple pen line freehanded across the browser window
Created January 3, 2016 20:06
Some coding challenges for the AO front end team who are learning JavaScript
/*
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);
}
@MikeDigitize
MikeDigitize / Write a Jasmine like API for a global Assert function
Created January 3, 2016 20:04
Some coding challenges for the AO front end team who are learning JavaScript
// 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) {