Is there a dictionary implementation in JavaScript?
Something like this could work :
df2 = df %>%
group_by(day, product_code) %>%
summarise(amount_per_product = sales_per_day*price_per_unit) %>%
ungroup() %>%
group_by(day) %>%
summarise(total_per_day = sum(amount_per_product)