Skip to content

Instantly share code, notes, and snippets.

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

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 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');

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
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)}
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';
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 {
<!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() {