Solution to 2nd RProg-005 programming assignment (Coursera)