Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script>
function onUnload() {
import React from 'react';
import {reduxForm, Field, SubmissionError} from 'redux-form';
import Input from './input';
import {required, nonEmpty, exactLength, onlyNumbers} from './validators';
const exactLength5 = exactLength(5);
const API_BASE_URL =
process.env.REACT_APP_API_BASE_URL || 'http://localhost:8080/api';
export class DeliveryForm extends React.Component {
import React from 'react';
import Person from './person';
export default class PersonList extends React.Component {
constructor(props) {
super(props);
this.state = {
people: [
{
import React from 'react';
export default function AddForm(props) {
return (
<form onSubmit={e => props.onSubmit(e)}>
<label htmlFor="textInput">Item to add:</label>
<input
id="textInput"
type="text"
onChange={e => props.onChange(e)}

Two of the most commonly used data structures in web development are stacks and queues. The history of pages visited in a web browser and the undo operation in a text editor are examples of operations made possible using stacks. The handling of events in web browsers often uses a queue data structure.

Stack

A stack is a data structure that stores elements in a LIFO (Last In First Out) order. It's like a stack of plates in your kitchen. When a plate is added, it is pushed towards the bottom of a stack. The last plate that you stack becomes the one on the top of the stack and it is the first one that you get to use.

A stack has two basic functions:

  • push(): places data onto the top of a stack
  • pop(): removes data from the top of the stack
function jediName(firstName, lastName) {
return lastName.slice(0, 3) + firstName.slice(0, 2);
}
console.log(jediName('Beyonce', 'Knowles'));
function beyond(num) {
if (num === Infinity || num === -Infinity) {
console.log('And beyond');

String, number, and logic drills

Jedi name

Write a function called jediName which takes two arguments:

  • firstName - a person's first name
  • lastName - a person's last name

The function should return the person's Jedi name. A Jedi name is formed from the first three letters of the last name, and the first two letters of the first name. For example, jediName('Beyonce', 'Knowles') should return 'KnoBe'.

function repeat(fn, n) {
for (var i=0; i<n; i++) {
fn();
}
};
function sayHello() {
console.log('Hello');
}

Higher-order function drills

Functions as arguments

  • Create a function called repeat which takes two arguments:
    • The first argument should be an arbitrary function, fn
    • The second argument should be a number, n
  • repeat should loop n times
  • Each iteration of the loop, it should call fn
  • Create two more functions called hello and goodbye:
@oampo
oampo / exercise-5.md
Last active September 28, 2016 21:56

Testing your components

  • Add a test file for each component to the test directory.
  • Use shallow or full DOM rendering to test that each component is rendered correctly, and responds to its input props how you would expect.