Given an array, select the closest match to input

Say I have a library of tops with different colors and a control top that oscillates in hue, how might I select the top from the library that most closely matches the current color of the control top? Forgive me I have very little scripting experience.