Skip to content

Instantly share code, notes, and snippets.

View nkabrown's full-sized avatar

Nathan Brown nkabrown

View GitHub Profile
@nkabrown
nkabrown / index.js
Last active July 25, 2016 21:22
requirebin sketch
const choo = require('choo');
const html = require('choo/html');
const app = choo();
// formula: tip total = (tip amount / 100) * bill amount
app.model({
state: { percent: ' ', amount: ' ', tip: ' ', total: ' ' },
reducers: {
calculateTip: (data, state) => {
@nkabrown
nkabrown / fibonacci.md
Last active July 29, 2016 18:08
C4Q Access Code — Application Workshop

Write a function that takes in an integer and returns an array of that size filled with the Fibonacci sequence.

function fibonacci(size) {
  // create an empty array to store our fibonacci sequence values
  var fibArray = [];
  
  // iterate the value of the size argument
  for (var i = 0; i < size; i++) {
 // if the array contains less than two elements push the value 1 into the array

Choo Notes

choo

Models are where state is contained and methods for updating the state are defined. All logic is centralized within models.

Views are functions that return a DOM tree of elements.

choo's tagged template string html builder is the yo-yo library — A tiny library for building modular UI components using DOM diffing and ES6 tagged template literals.

@nkabrown
nkabrown / fizzbuzz.md
Last active July 29, 2016 18:08
C4Q Access Code — Application Workshop

FizzBuzz

function fizzbuzz(times) {
  for (var i = 1; i <= times; i++) {
    // you must test for both first
    if (i % 5 === 0 && i % 3 === 0) {
      console.log('FizzBuzz');
    } else if (i % 5 === 0) {
 console.log('Buzz');
@nkabrown
nkabrown / function-migrations.md
Last active July 29, 2016 18:08
C4Q Access Code — Application Workshop

Migrate Functions

Migrate building a simple array

var arrayBuilder = function(size) {
  // create an empty array to store our values
  var array = [];
  
  // iterate the value of the argument
@nkabrown
nkabrown / functions-workout.md
Last active July 29, 2016 18:09
C4Q Access Code — Application Workshop

Functions Workout

Functions represent computations to be performed.

A return statement causes a function to cease execution and return a value to the caller. If no value is specified the return statement will return the undefined value.

The difference between parameters and arguments. Parameters are used in function definition.

function loop(array) { // array is a parameter that defines what is passed into the function
@nkabrown
nkabrown / array-workout.md
Last active July 29, 2016 18:09
C4Q Access Code — Application Workshop

Array Workout

Find min & max within an array

Given an array write a program that returns the largest element. Then try the smallest element.

// construct an array of values
var arr = [25, 101, 66, 10, 99];
@nkabrown
nkabrown / index.html
Last active June 7, 2016 18:03
selection ui
<!DOCTYPE html>
<meta charset="utf-8">
<title>D3 Selection UI</title>
<style>
html,
body {
margin: 0;
padding: 0;
}
@nkabrown
nkabrown / modulo.md
Last active May 12, 2016 15:21
short discussion of modulo

Modulo

Wolfram defines the modulo operation as "m mod n is the remainder on division of m by n. The sign of m mod n for real m, n is always the same sign of n."

Python has a true modulo operator.

-5 % 2
# => 1