I have an array that looks like this:
Arr=[{"cause" : 1 , "solution" : "change"},
{"cause" : 1 , "solution" : "rechange"},
{"cause" : 2 , "solution" : "alter settings"},
{"cause" : 1 , "solution" : "change"},
{"cause" : 3 , "solution" : "change"},
{"cause" : 4 , "solution" : "change"},
{"cause" : 5 , "solution" : "reload"}];
I am trying to get calculate the occurrence of the solution based on the cause and store it in an array in percentages. For example, the occurrence of cause 1 and solution change is 2/3 so it will be 66.66% by multiplying it with 100. And here is my progress so far:
var ctr = [];
var percentageArr = [];
for (var a=0;a< Arr.length;a++){
for (var b=0;b< Arr.length;b++){
if (Arr [b]. cause == Arr [a]. cause){
ctr++;
}
}
ctr=ctr/( Arr.length)*100;
ctr=ctr.toFixed(2);
percentageArr.push(ctr);
ctr=0;
}
Now with this output, I can get the percentage of the causes. But i am trying to get the percentage of the solutions based on the causes. I am currently thinking of adding another nested loop to check for the solution but am open to any suggestions