lundi 5 décembre 2016

Parsing data from a file and storing in an object

OK so I had a job interview with a coding challenge which I completely blew..

I am hoping someone can help me solve this so that I can at least understand what I was missing so I can do better next time something like this comes up.

I was asked to create a parser for the following data:

Data = {
    Name = "Macrosoft",
    Launched = 2006,
    Scores = {
        Players = {
            Josh = 46,
            June = 98
        },
        Rewards = ( 50, 40, 20 ),
        Min = 1,
        Max = 100
    },
    Games = (
        "Evo",
        "Gun Star",
        "Nuka"
    )
}

required functions:
 data.GetStr("Name"); // returns Macrosoft
 data.GetNum("Launched"); // returns 2006
 data.GetData("Scores").GetData("Players").GetNum("June"); // returns 98
 data.GetArray("Games").GetStr(1); // returns Evo
 data.FindNum("June"); // returns 98


Details:

All elements have an identifier like Data, Name, Launched, etc 

All elements have some data which come after the identifier and 
the char '=' the data can be:
    String 
    Int (Launched, Min and Max)
    array ( arrays defined between '(' and ')' )
    other data (Data, Scores, Players)

Aucun commentaire:

Enregistrer un commentaire