module SoPerf::ValueFinder

Public Instance Methods

closest(arr, val) click to toggle source
# File lib/soperf/soperf_helpers.rb, line 26
def closest(arr, val) #returns the index of the closest-matching element of the array
  closest = arr.map { |elem| (elem-val).abs }
  closest.index(closest.min)
end