I have the following information:
Name, GPA 2010, GPA 2011
Adam, [2010, 3.4], [2011, 3.9]
Ben, [2010, 3.4], [2011, 3.9]
Charlie, [2010, 3.4], [2011, 3.9]
I'd like to be able to do the following:
- Sort alphabetically by name
- Sort by the GPA achieved in 2010
- Sort by the GPA achieved in 2011
- Add new users to the list iff their name isn't already on it.
What is the most economical JavaScript data structure to use for this sort of sorting?
Currently I have this:
var grades = {
'Adam': [[2010, 3.4], [2011, 3.9]],
'Ben' : [[2010, 3.4], [2011, 3.9]],
'Charlie' : [[2010, 3.4], [2011, 3.9]] };
This makes it easy to achieve point 4 (if (name in grades === false)
) and reasonably easy to achieve point 1, but quite fiddly to achieve point 2 or 3.