added solution to assignment

defined the 2 functions as asked in the assignment and verified results
in RStudio