My implementation of listOfN
listOfN implemented by the book