Skip to content

Instantly share code, notes, and snippets.

@marka2g
Created October 24, 2017 00:39
Show Gist options
  • Select an option

  • Save marka2g/d50c3782641d6ec6dc276ca02141fae9 to your computer and use it in GitHub Desktop.

Select an option

Save marka2g/d50c3782641d6ec6dc276ca02141fae9 to your computer and use it in GitHub Desktop.
Order By Index
days_array = ["everyday", "school_nights", "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
def order_days(hashes)
days_indexes = {}
days_array.each_with_index do |item, index|
days_indexes[item] = index
end
hashes.sort_by do |schedule|
days_indexes.fetch(schedule[:day].downcase)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment