I want to make this into a function:
var meanPoints = d3.mean(data, function(d) {return d['total points'] });
console.log(meanPoints);
This works and gives me the mean of the total point of my json file.
But if i try to make a function like so:
function meanVak(vak) {
d3.mean(data, function(d) {return d [vak] });
}
var meanPoints = meanVak('total points');
console.info(meanPoints);
It comes back as undefined.
Because you don’t have
returnstatement:Side note: by default functions without
returnstatement returnundefined.