Vote count:
0
I have an array of hashes similar to this:
[ {"student": "a","scores": [{"subject": "math","quantity": 10},{"subject": "english", "quantity": 5}]}, {"student": "b", "scores": [{"subject": "math","quantity": 1 }, {"subject": "english","quantity": 2 } ]}, {"student": "a", "scores": [ { "subject": "math", "quantity": 2},{"subject": "science", "quantity": 5 } ] } ]
Is there a simpler way of getting the output similar to this except looping through the array and finding a duplicate and then combining them?
[ {"student": "a","scores": [{"subject": "math","quantity": 12},{"subject": "english", "quantity": 5},{"subject": "science", "quantity": 5 } ]}, {"student": "b", "scores": [{"subject": "math","quantity": 1 }, {"subject": "english","quantity": 2 } ]} ]
Merging hash values in an array of hashes based on key
Aucun commentaire:
Enregistrer un commentaire