Implemented the functions for Coursera programming assignment.