I'm trying to count the number of odd and even numbers in an array by using the Array.reduce() method. When I run the below code, I get the error "odd is not defined." How/where do I define odd to get this code to work?
var numbers = [5, 3, 8, 6, 9, 1, 0, 2, 2];
var oddEvenCounts = numbers.reduce(function(counts, number) {
if (number % 2 === 1) {
counts[odd]++
} else {
counts[even]++;
}
return counts;
}, {});
counts.oddandcounts.eveninstead ofcounts[....]or evencounts["odd"]andcounts["even"]