Looking to create a function that can calculate ratios based on specific keys and control which keys are eligible for ratio calculation.
num = [{"HCOName":8919,"timestamp":"2019-01-01T00:00:00.000Z","Territory":"USA"},
{"HCOName":8275,"timestamp":"2019-02-01T00:00:00.000Z","Territory":"USA"},
{"HCOName":8107,"timestamp":"2019-03-01T00:00:00.000Z","Territory":"USA"},
{"HCOName":8255,"timestamp":"2019-04-01T00:00:00.000Z","Territory":"BRAZIL"},
{"HCOName":8802,"timestamp":"2019-05-01T00:00:00.000Z","Territory":"BRAZIL"}];
den = [{"HCP":9,"timestamp":"2019-01-01T00:00:00.000Z","Territory":"USA"},
{"HCP":5,"timestamp":"2019-02-01T00:00:00.000Z","Territory":"USA"},
{"HCP":7,"timestamp":"2019-03-01T00:00:00.000Z","Territory":"USA"},
{"HCP":2,"timestamp":"2019-05-01T00:00:00.000Z","Territory":"CANADA"}];
commonDimesion= ["timestamp", "Territory"]
function ratio(num,den,commonDimesion){
<some code>
}
anticipated outcome:
[{"ratioResult":991,"timestamp":"2019-01-01T00:00:00.000Z","Territory":"USA"},
{"ratioResult":1655,"timestamp":"2019-02-01T00:00:00.000Z","Territory":"USA"},
{"ratioResult":1158.14,"timestamp":"2019-03-01T00:00:00.000Z","Territory":"USA"}]