Retail Programming Challenge

    How to help the seller to determine whether there is a product with the desired characteristics?

    Example
    Often coming to the shoe store and choosing your favorite model, we wait for the sellers to determine if there is a suitable size.

    Given


    List of variations . Each variation in turn contains a list of attributes and their values.

    example-data.json
    [
      {
        "Size": 37,
        "Color": "Brown",
        "Lock": "Zipper"
      },
      {
        "Size": 37,
        "Color": "Black",
        "Lock": "Zipper"
      },
      {
        "Size": 38,
        "Color": "Blue",
        "Lock": "Laces"
      },
      {
        "Size": 39,
        "Color": "Blue",
        "Lock": "Laces"
      },
      {
        "Size": 39,
        "Color": "Brown",
        "Lock": "Zipper"
      },
      {
        "Size": 39,
        "Color": "Brown",
        "Lock": "Laces"
      },
      {
        "Size": 40,
        "Color": "Brown",
        "Lock": "Laces"
      }
    ]
    


    It is necessary to create an interface by which the seller, having chosen the necessary properties, can determine whether the goods are in stock or not.

    Conditions:


    • The variation contains the complete list of attributes (there can be no variation with unknown values, if the attribute is present in one variation, then it is in all)
    • The length of the list of variants of attribute values ​​varies from attribute to attribute (one attribute can take one of two values, the other one of four, etc.)
    • One attribute can have only one value.

    Functional:


    The interface is a list of lists, where at the first level is an attribute type, at the second its value.

    Each element can be in 3 states:

    • Available to choose - White
    • Active - Blue
    • Available with other combinations - Gray

    At the beginning, all elements are available for selection.



    After selecting one of the attributes, all the others are revised.



    We chose 37 (Could start with brown, the logic is the same). All other sizes are white (as they are by condition). Blue is not. It becomes gray, the rest are white. 37 is only on Lightning. So lightning is automatically selected. And here, attention! 40 is not the size of lightning, it means 40 becomes gray.

    If we suddenly needed a blue color, then the size is reset (since there is no blue 37) and the lock (since there is no 37 lightning, if it were, it would remain selected), the laces are automatically selected (because blue There is only with laces), and the sizes become available 38, 39.



    The task is applicable as:

    • Practice for learners programming
    • Test task for the selection of candidates
    • Just an interesting pastime for experienced developers.

    Please: do not post the solution to the problem in the comments.

    Only registered users can participate in the survey. Sign in , please.

    Task for developer level


    Also popular now: