i have a json like this:
[{
"semester":"1",
"classification":"Excellent",
"schoolYear":"2018"
},
{
"semester":"2",
"classification":"Intermediate",
"schoolYear":"2018"
},
{
"semester":"1",
"classification":"Excellent",
"schoolYear":"2018"
},
{
"semester":"2",
"classification":"Good",
"schoolYear":"2017"
},
{
"semester":"1",
"classification":"Excellent",
"schoolYear":"2017"
},
{
"semester":"2",
"classification":"Good",
"schoolYear":"2017"
},
{
"semester":"1",
"classification":"Excellent",
"schoolYear":"2017"
},
{
"semester":"2",
"classification":"Fail",
"schoolYear":"2017"
},
{
"semester":"1",
"classification":"Good",
"schoolYear":"2017"
}]
and i want the output following this format by a function:
[
{
schoolYear: '2018',
semesters: [
{
Excellent: 2,
Good: 0,
Intermediate: 0,
Average: 0,
Weak: 0,
Fail: 0
},
{
Excellent: 0,
Good: 0,
Intermediate: 1,
Average: 0,
Weak: 0,
Fail: 0
}
]
},
{
schoolYear: '2017',
semesters: [
{
Excellent: 3,
Good: 1,
Intermediate: 0,
Average: 0,
Weak: 0,
Fail: 0
},
{
Excellent: 0,
Good: 2,
Intermediate: 0,
Average: 0,
Weak: 0,
Fail: 1
}
]
}
]
as you can see, the output is an array, each element in the array has 2 attributes, the schoolYear is a String, and the semesters is an array which contains 2 elements only, the first element at index 0 is for the "semester": "1" according to the input and the second element at index 1 is for the "semester": "2", of course.
i want to say thank to you to take time help me out, you can modify the code in this codesandbox demo here, once again, thank you very much and have a good day