Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @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
- ))
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement