Skip to content

Instantly share code, notes, and snippets.

@thunklife
Last active November 15, 2018 20:51
Show Gist options
  • Save thunklife/1959793251b8982842ad997c624952f9 to your computer and use it in GitHub Desktop.
Save thunklife/1959793251b8982842ad997c624952f9 to your computer and use it in GitHub Desktop.

November Katas

Algorithms

Binary Search

Given an ordered list of elements, and an element you are searching for, provide the position of the element if it is in the list. A binary search follows these steps:

  1. Check if the middle element is the item you are looking for
    • If so, return the position of the element
  2. If the "guess" is too low, repeat at step 1 with the right side of the list
  3. If the "guess" is too high, repeat at step 1 with the left side of the list

Selection Sort

Given a list of things that can be sorted, numbers for example, sort the list from smallest to largest and/or largest to smallest. A selection sort follow these steps:

  1. Find the largest, or smallest depending of the sort, item in the list
  2. Move that item to the top of a new list and remove it from the source list
  3. Repeat at step 1 until the source list is empty
  4. Return the sorted list

Quick Sort

Breadth-first Search

Depth-first Search

Domain Driven Design

Below is an example of some JSON that represents a 'card' the specifs of a what a card is isn't important. What is important are the depencies between the fields. For example, only a video card can have a video_url, or every completed card is also an assigned card, etc. The problem with this model is that it doesn't enforce any invariants. Rewrite this model to that those invariants are enforced.

{
 "assigned_date": string                 // Or null. Valid values are in YYYY-MM-DD format
 "complete_date": string                 // Or null. Valid values are in YYYY-MM-DD format. A card must first be assigned,
 "image_url": string                     // Never null. A fully qualified URL to an image,
 "content_text": string                  // Or null. Applies only to articles",
 "content_title": string                 // Or null. A fully qualified URL to an image. Applies only to articles",
 "content_image_url": string             // Or null. A fully qualified URL to an image. Applies only to articles",
 "content_video_url": string             // Or null. A fully qualified URL to an image. Applies only to videos",
 "content_checklist:" string[]           // Or null. Applies only to checklists,
 "title": string                         // Never null,
 "type": string                          // Never null. Valid values are video, article, checklist
}

If time permits, write some functions for these cards. For example, assigning and unassigning a card, completing a card, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment