Giter Club home page Giter Club logo

condensed-opening-hours's Introduction

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! ๐ŸŽ‰

condensed-opening-hours's People

Contributors

timotheus90 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.