Created
March 6, 2017 01:52
-
-
Save mytholog/39cb5ff42916103e50a007f5fd0eece7 to your computer and use it in GitHub Desktop.
closest number out of array
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
const counts = [4, 9, 15, 6, 2]; | |
const goal = 5; | |
counts | |
.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