In the code for the contrast function, the farthest variable is set to: farthest: onWhite == max? .WHITE : .BLACK.
The max variable is set to Math.max(contrastOnBlack, contrastOnWhite);, and min is either contrastOnBlack or contrastOnWhite. So, comparing onWhite to contrastOnBlack or contrastOnWhite would be comparing two different things. So I think farthest should be changed to: farthest: contrastOnWhite == max? .WHITE : .BLACK
In the code for the contrast function, the farthest variable is set to: farthest: onWhite == max? .WHITE : .BLACK.
The max variable is set to Math.max(contrastOnBlack, contrastOnWhite);, and min is either contrastOnBlack or contrastOnWhite. So, comparing onWhite to contrastOnBlack or contrastOnWhite would be comparing two different things. So I think farthest should be changed to: farthest: contrastOnWhite == max? .WHITE : .BLACK