Code Monkey home page Code Monkey logo

openinghours-challenge25's Introduction

Opening Hours

JL coding challenge 25


Solution

Solution output is of format...

Mon: Closed | Tue-Thu: 5pm-10pm | Wed-Thu: 12pm-2pm | Fri-Sat: 12pm-10.30pm | Sun: 12pm-5pm


Instructions

An app that aggregates information about retail businesses shows the opening hours for each shop.

The app shows the opening hours on a single line of text which is obtained from a 3rd party Api.

Unfortunately the Api has changed so that it no longer returns a single line of text, and instead returns data as an array of opening times, each containing array of days that the opening times apply to.

If opening time and closing time is both 00:00 then the business is closed on that day.

In this challenge you are required to create a function to convert the array of opening times into a single line of text.

It's up to you what the resulting text looks like as long as it fits the conflicting requirement of being both understandable and compact.


Example data

Original text for opening hours was...

{ "openingHours":"Mon-Fri:12pm-10pm, Sat-Sun:12pm-11pm"}

But is now...

{ "openingHoursSpecification":
    [    
        {
            "dayOfWeek":[
                "Monday",
                "Tuesday",
                "Wednesday",
                "Thursday",
                "Friday"
            ],
            "opens":"12:00",
            "closes":"22:00"
        } ,
        {
            "dayOfWeek":[
                "Saturday",
                "Sunday"
            ],
            "opens":"12:00",
            "closes":"23:00"
        }
    ]
}

More complex version...

{ "openingHoursSpecification":
    [    
        {
           "dayOfWeek":[
              "Monday"
           ],
           "opens":"00:00",
           "closes":"00:00"
         },
        {
           "dayOfWeek":[
               "Tuesday",
               "Wednesday",
               "Thursday"
           ],
           "opens":"17:00",
           "closes":"22:00"
        },
        {
           "dayOfWeek":[
                "Wednesday",
                "Thursday"
           ],
           "opens":"12:00",
            "closes":"14:00"
        },
        {
           "dayOfWeek":[
                "Friday",
                "Saturday"
           ],
           "opens":"12:00",
           "closes":"22:30"
         },
         {
            "dayOfWeek":[
                "Sunday"
            ],
            "opens":"12:00",
            "closes":"17:00"
          }
    ]
}

openinghours-challenge25's People

Watchers

James Cloos avatar Matt Thompson 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.