Skip to content

timotheus90/condensed-opening-hours

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 

Repository files navigation

Coding Challenge: Simplify Business Hours

Problem Description

Your task is to write a function that simplifies the business hours of a store. You will be provided with an array of JSON objects representing the hours of operation for each day of the week. Your function should return a string that represents the simplified version of the business hours.

Input Format

You will receive an array of objects. Each object contains:

  • dayOfWeek: The day of the week as a string (e.g., "Montag", "Dienstag", etc.)
  • from: The opening time of the store in HH:MM:SS format
  • to: The closing time of the store in HH:MM:SS format
[
  {"dayOfWeek": "Montag", "from": "07:00:00", "to": "22:00:00"},
  {"dayOfWeek": "Dienstag", "from": "07:00:00", "to": "22:00:00"},
  ...
]

Output Format

Your function should return a string that condenses the business hours into a simplified representation.

"Mo-Di 10:00 - 20:00, Mi-Do 09:00 - 18:00, Fr-So 09:00 - 14:00"

Constraints

  • The days will be sorted in the order: Montag, Dienstag, ..., Sonntag.
  • The time will be in 24-hour format.

Examples

Example 1

Input

	data := `[{"dayOfWeek": "Montag", "from": "10:00:00", "to": "20:00:00"},
	          {"dayOfWeek": "Dienstag", "from": "10:00:00", "to": "20:00:00"},
	          {"dayOfWeek": "Mittwoch", "from": "09:00:00", "to": "18:00:00"},
	          {"dayOfWeek": "Donnerstag", "from": "09:00:00", "to": "18:00:00"},
	          {"dayOfWeek": "Freitag", "from": "09:00:00", "to": "14:00:00"},
	          {"dayOfWeek": "Samstag", "from": "09:00:00", "to": "14:00:00"},
	          {"dayOfWeek": "Sonntag", "from": "09:00:00", "to": "14:00:00"}]`

Output

"Mo-Di 10:00 - 20:00, Mi-Do 09:00 - 18:00, Fr-So 09:00 - 14:00"

Tips πŸš€

  • Consider using a loop to iterate through the days and group the ones with the same business hours.
  • Keep track of sequences (consecutive days with the same hours) to simplify the output.

Evaluation Criteria 🌟

  • Correctness: Does the code perform as required?
  • Readability: Is the code easy to follow?
  • Simplicity: Is the code straightforward and concise?

Good luck and happy coding! πŸŽ‰

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published