Adding the index argument to the function argument in populateMap

Also adding tests (there should've been tests...)
could you add another test for the edge case where `keys = []`?