I need a function
combineListOnKeys(listOfObjs, listOfKeys)
which will accept the following:
var listOfObjs =
[
{ name: john, state: ny, age: 12}
, { name: john, state: ny, age: 22}
, { name: john, state: dc, age: 32}
, { name: john, state: dc, age: 42}
, { name: paul, state: ca, age: 52}
]
var listOfKeys = ["name", "state"]
and returns this:
combineListOnKeys(listOfObjs, listOfKeys)
[
{ "name": john, "state": ny, "age": [12, 22]}
,{ "name": john, "state": dc, "age": [32, 42]}
,{ "name": paul, "state": ca, "age": [52]}
]
In essence, I try to match several specified keys that share all these objects, and take the remaining unspecified keys and combine them into a list, thereby removing some duplicate information.
I am using underscore.js, but I can not find an example of this problem in the docs. Thanks in advance!