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:
- Check if the middle element is the item you are looking for
- If so, return the position of the element
- If the "guess" is too low, repeat at step 1 with the right side of the list
- If the "guess" is too high, repeat at step 1 with the left side of the list
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:
- Find the largest, or smallest depending of the sort, item in the list
- Move that item to the top of a new list and remove it from the source list
- Repeat at step 1 until the source list is empty
- Return the sorted list
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.