Skip to content
Advertisement

Find the nearest value to the given one in set

I am trying to find the closest number to 5 in set b. This is my code.

JavaScript

Advertisement

Answer

You can use the key argument to min to achieve this:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement