Created
December 11, 2011 07:21
-
-
Save gf3/1459052 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find closest point to a set of points. | |
findClosestPoint = (needle, haystack) -> | |
(init = new Point).diff = Number.MAX_VALUE | |
comparator = (memo, point) -> | |
point.diff = Math.abs(needle.x - point.x) + Math.abs(needle.y - point.y) | |
if point.diff < memo.diff then point else memo | |
_.foldl haystack, comparator, init | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment