By remembering the keys already compared in repeating a comparison is avoided. Thanks: https://stackoverflow.com/a/32660766