Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
closest in range
/**
* @desc gets the closes number in a range of numbers
* @param {Array} list
* @param {Number} goal
* @author a mix of stackoverflowers
*/
const closestInRange = (list, goal) => (
list.reduce((prev, curr) => (
Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev
))
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.