Given an array of numbers nums
, and a given number given_num
:
nums = [100, 200, 400, 800, 1600, 3200, 6400, 128000]
given_num = 900
Get the number closest to the given_num
from the array nums
.
In this example, the returned value should be 800
.
Ruby:
Shamelessly taken from Stack Overflow 🙃 I was in a much more of a "just give me the answer" mood than "let's figure it out" mood.