Here is a nice little quick
function closest(deg,ar) { return ar.sort(function(a,b){var c = deg; return Math.min(360 - (ac),Math.abs(ac)) - Math.min(360 - (bc),Math.abs(bc))}) } var myArray = [355, 280, 200, 181, 90, 30]; alert(closest(180,myArray));
Sorts and returns the array according to which it is closest to the degree provided. Index 0 is closest. This completes, making 355 closer to 0 than 10.
Joseph Marikle
source share