I need to sum key values (K1, K2, K3...) of machines (M1, M2, M3...) for each shift (S1, S2, S3) and create a new object (Given below)
I lost my patience with jquery $.each and forEach methods (since I need to handle 5 levels of objects) and came across UnderscoreJS.
I understand that I should use multiple combinations of functions for objects http://underscorejs.org/#objects but due to being a pure front-end guy with minimal knowledge in queries and DB, I couldn't find the right way to do that.
Given JSON structure:
var data = {
"28-11":{
"S1":{
"M1":{
"K1": 10,
"K2": 12,
"K3": 15
},
"M2":{
"K1": 8,
"K2": 6,
"K3": 5
}
},
"S2":{
"M1":{
"K1": 8,
"K2": 6,
"K3": 5
},
"M2":{
"K1": 10,
"K2": 12,
"K3": 15
}
}
}
}
I need to obtain the following:
var allShiftsData = {
"28-11":{
"M1":{
"K1": 18,
"K2": 18,
"K3": 20
},
"M2":{
"K1": 18,
"K2": 18,
"K3": 20
}
}
}