In the loop portion of this function why are we having to set ‘let index = -1’ before beginning the loop? Is that just so the index will show as -1 when no keys are found?
It looks that way. We have two options, either set it before the conditional testing and return the variable after the loop, or simply return
-1 after the loop. It is common for lookup methods to return -1 when no match is found, so making our program do that just brings it in line with normal expectations.