0

How can I count the number of occurrences in an array of arrays?

So I have an array of around 280 arrays, the goals of a soccer team as such:

var goalsScored = [["Sun Apr 28 2009","Juventus - Milan","2 - 3","Del Piero","Dida",7],["Sun Apr 28 1999","Juventus - Milan","2 - 3","Zidane","Peruzzi",44], ["Sat June 8 2009","Juventus - Milan","1 - 0","Nedved","Abbiati",7].....n=280]

So basically I have a list of goals and I want to count the number of goals scored each minute where goalsScored[5] refers to the minute. I also want to maintain the data, I don't want to simply count how many goals were scored in the 7th minute, but I would like to know when, by who...etc.

So my question here is how can I do that? And what would be the best data structure? Should I have an array for each minute, or an array of arrays of arrays as such:

goalsMin = [[minute, count[date ,teams, result,scorer, goalkeeper]],[minute,count[date,teams,result,scorer,goalkeeper]]]

Does that make sense?

1 Answer 1

1

You could keep an array of arrays (one array for each minute). The data could be mentained using Object, something like this:

goal = {
    date : "Sun Apr 28 2009",
    match : "Juventus - Milan",
    score : "2-3",
    player : "Del Piero",
    goalkeeper : "Dida"
};

You will insert data in the structure like this:

goals[minute].push(goal);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.