I am so ridiculously lost with JS...I've been trying literally for hours to do stuff that takes 5 seconds to do in R or Python. Trying to learn just for this one homework.
Lets say I have an object like this:
myObject = [ {'location': 'california', 'day': 'wednesday', 'company': 'Tesla'},
{'location': 'washington', 'day': 'tuesday', 'company': 'Microsoft'},
{'location': 'california', 'day': 'wednesday', 'company': 'Tesla'},
{'location': 'california', 'day': 'monday', 'company': 'Apple'},
{'location': 'california', 'day': 'monday', 'company': 'SalesForce'}
{'location': 'washington', 'day': 'tuesday', 'company': 'Microsoft'},
{'location': 'california', 'day': 'wednesday', 'company': 'Apple'}
]
I want to group by location and day, and count the number of different companies and get an output like this:
myOutputObject = [ {'location': 'california', 'day': 'wednesday', 'count':2},
{'location': 'washington', 'day': 'tuesday', 'count':1},
{'location': 'california', 'day': 'monday', 'count':2}
]
Coming from a python background JS is a nightmare in a box to me.
I tried just creating a 'count' key in every element and setting it 0 to start with like this:
var dataset = []
dataset = data.forEach(function(d){
d['count'] = 0;
return d
})
console.log(dataset);
Nothing...zilch...undefined...
Can someone please be kind enough to explain to me how to get my head around this nonsense?