Skip to content

Instantly share code, notes, and snippets.

@cmatheson
Created May 16, 2013 00:14
Show Gist options
  • Save cmatheson/5588476 to your computer and use it in GitHub Desktop.
Save cmatheson/5588476 to your computer and use it in GitHub Desktop.
# returns the closest 15 minute interval
def closest(n)
closest_interval = [0, 15, 30, 45, 60].map { |m|
[m, (m - n).abs]
}.min_by { |_, minutes_away|
minutes_away
}
closest_interval.first
end
%w(1 7 14 16 27 30 33 44 55).each { |x|
p closest(x.to_i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment