Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Jason Belcher JasonBBelcher

🎯
Focusing
View GitHub Profile
View recursion_examples.js
// 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: {
View mapfilterreduce.js
// 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;
}
View mapfilterreduce.js
// 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;
}
View dataStore.js
// 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()
View inherit-with-classes.js
class Dinosaur {
constructor(name) {
this.poo = this.poo.bind(this);
this.name = name;
}
poo() {
console.log(`${this.name} poo poos. wooo it stinks!`);
}
@JasonBBelcher
JasonBBelcher / inheritWithoutClasses.js
Created Jul 22, 2019
Inheritance and composition without classes.
View inheritWithoutClasses.js
// 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 };
@JasonBBelcher
JasonBBelcher / factories.js
Created Jul 21, 2019
Composing with factory functions
View factories.js
// 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",
@JasonBBelcher
JasonBBelcher / searchAndGetPaginated.js
Last active Jul 21, 2019
Async currying factory to get all paginated results
View searchAndGetPaginated.js
// 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())
You can’t perform that action at this time.