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
// Simple recursion example that walks down a bunch of nested objects till it finds a function. | |
const testObj = { | |
value: { | |
node: { | |
value: { | |
node: { | |
value: { | |
node: { | |
value: { |
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
// implement map// implement map | |
function map(array, cb) { | |
let i; | |
let mapped = []; | |
for (i = 0; i < array.length; i += 1) { | |
total.push(cb(array[i])); | |
} | |
return mapped; | |
} |
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
// implement map | |
function map(array, cb) { | |
let i; | |
let total = []; | |
for (i = 0; i < array.length; i += 1) { | |
total.push(cb(array[i])); | |
} | |
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
// create a dataStore lib in JavaScript using a factory | |
function dataStore(dataset, interface) { | |
/* *********************** | |
PRIVATE FIELDS & METHODS | |
**************************/ | |
// create a random id for lookup | |
function createId() { | |
return Math.random() |
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
class Dinosaur { | |
constructor(name) { | |
this.poo = this.poo.bind(this); | |
this.name = name; | |
} | |
poo() { | |
console.log(`${this.name} poo poos. wooo it stinks!`); | |
} |
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
// inherit stuff without classes | |
function Dinosaur(name) { | |
function poo() { | |
console.log(`${name} poo poos.`); | |
} | |
function bite() { | |
console.log(`${name} bites and chomps!`); | |
} | |
return { poo, bite }; |
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
// Composition over inheritance with Factory functions | |
// No classes were hurt in the making of this file. | |
// single factory functions utilizing higher order functions | |
// to pass arguments without returning the object at same time | |
function synthFactory(manufacturer, type, model) { | |
return function() { | |
return { | |
instrument: "synth", |
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
// Async, curried, recursive factory to get all paginated results | |
function searchAndGetPaginated(baseUrl) { | |
return function(resource, searchQuery) { | |
return new Promise((resolve, reject) => { | |
search(`${baseUrl}/${resource}/${searchQuery ? searchQuery : ""}`); | |
const allPages = []; | |
function search(url) { | |
fetch(url) | |
.then(res => res.json()) |