Skip to content
Advertisement

Convert values to percents based on two other values in array of objects

I have an array of objects:

JavaScript

I want to convert val1 to percentages based on the date and device.

So on 2018-01-01 if the device is iphone I want the vals to be for example: val1 to be 10%, 23% & 67% respectively.

My code so far:

JavaScript
JavaScript

While I am able to group the data by 2 keys, I am not sure how to convert the val1’s to %’s.

I am not sure how to go from here to get this as the data:

JavaScript

Advertisement

Answer

As per your explanation, I tried this in completely different way.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement