The gradient should use the shortest way
If the diff between 2 hues is greater then 180 it should use the other direction.

In the above example you can see that it goes around the whole color wheel to go from light red to red instead of using the other direction.
What are the input arguments you used to get that output?
I haven't touched this code in quite a while, but off the top of my head the last argument is the # of steps to take. What if the sign of that value indicated direction? E.g. Gradient('blue', 'red', 10) would go one direction and Gradient('blue', 'red', -10) would go the other direction?
The problem comes when you have more then two colors as you can see in this example. The colors are:
"#3FB8AF", "#7FC7AF", "#DAD8A7", "#FF9E9D", "#FF3D7F"