Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gaku-sei/28448e5ad5165bd7944d2eca19a5cf6a to your computer and use it in GitHub Desktop.
Save gaku-sei/28448e5ad5165bd7944d2eca19a5cf6a to your computer and use it in GitHub Desktop.
Pair Programming Exercises

Number to Ordinal

Finish the function numberToOrdinal, which should take a number and return it as a string with the correct ordinal indicator suffix (in English). That is:

  • numberToOrdinal(1) ==> '1st'
  • numberToOrdinal(2) ==> '2nd'
  • numberToOrdinal(3) ==> '3rd'
  • numberToOrdinal(4) ==> '4th'

Fluid Calculator

The goal is to implement simple calculator which uses fluent syntax (pseudo code)

  • Calc.new.one.plus.two # Should return 3
  • Calc.new.five.minus.six # Should return -1
  • Calc.new.seven.times.two # Should return 14
  • Calc.new.nine.divided_by.three # Should return 3

In js

  • new Calc().one().plus().two()

String to Number

V1 I'd like an efficient function that can convert a single character string (or just a char if the language supports this type) to an int:

  • parse("1") # 1
  • parse("d") # doesn't work
  • etc...

V2 Can we improve this by supporting multi characters:

  • parse("23") # 23
  • parse("dd") # doesn't work

V3 Also support negative numbers:

  • parse("-23") # -23
  • parse("-dd") # doesn't work

V4 Now what about supporting floats:

  • parse("23.43") # 23.43
  • parse("dd.dd") # still doesn't work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment