Completed problem 6. Implementation probably not the most readable, but got good practice with passing function parameters.