Function Design Strategy

Source: http://www.ics.uci.edu/~kay/courses/31/design-recipe.html

  1. Write examples
  2. Write type contract
  3. Name the function and parameters
  4. Write description
  5. Write function body
  6. Test examples
/*
  (a: Number, b: Number) -> Number

  Return the greater of `a` and `b`

  Examples

      max(1, 2) // => 2
      max(2, 2) // => 2
      max(2, 1) // => 2
      max(-100, 1) // => 1
*/
function max(a, b) {
  return a > b ? a : b;
}