for (var i = 0; i < this.assessments.length; i++) { ..............
for (var j = 0; j < this.assessments[i]["Evaluation"].length; j++) { ..........
for (var k = 0; k < this.assessments[i]["Evaluation"][j]["EvaluationSection"].length; k++) { ..........
for (var l = 0; l < this.assessments[i]["Evaluation"][j]["EvaluationSection"][k]["EvaluationRating"].length; l++){ ..........
}
}
}
}
The Ouptut:
Microsoft Technologies : 87
Java Technologies:30
Microsoft Technologies: 40
I want to average of Percentage i.e (87+40)/2 if Title are same value in InterviewId 1.
The Ouptut should display like this:
Microsoft Technologies : 63.5
Java Technologies:30
How to do it?
I am waiting for your response.
Thanks in Advance.
You could create and maintain an array to store item contains title and percentage properties, you could create&push item into this array or update percentage property value while you loop through your data source assessments. Finally, you could dynamically
generate/output data list base this new array.
var dataarray = [];
//your code to loop through your data collection assessments
for (var i = 0; i < this.assessments.length; i++) {
//add new item to array dataarray, if the title does not exist in dataarray
if (not in dataarray) {
//create new item based on field value of assessments
var newitem = { "Title": this.assessments[i]["Evaluation"][j]["EvaluationSection"][k].Title, "Percentage": this.assessments[i]["Evaluation"][j]["EvaluationSection"][k].Percentage };
//add item to dataarray
dataarray.push(newitem);
} else {
//do calculation
//update item with same Title and update Percentage property value for dataarray
}
}
Best Regards,
Fei Han
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
52 Points
172 Posts
Average of percentage - JSON
Aug 09, 2016 11:02 AM|IamGuy84|LINK
Hi folks,
here is my Json:
In TypeScript:
The Ouptut:
Microsoft Technologies : 87
Java Technologies:30
Microsoft Technologies: 40
I want to average of Percentage i.e (87+40)/2 if Title are same value in InterviewId 1.
The Ouptut should display like this:
Microsoft Technologies : 63.5
Java Technologies:30
How to do it?
I am waiting for your response.
Thanks in Advance.
All-Star
40535 Points
6233 Posts
Microsoft
Re: Average of percentage - JSON
Aug 10, 2016 11:48 AM|Fei Han - MSFT|LINK
Hi IamGuy84,
You could create and maintain an array to store item contains title and percentage properties, you could create&push item into this array or update percentage property value while you loop through your data source assessments. Finally, you could dynamically generate/output data list base this new array.
Best Regards,
Fei Han