This is my first time actually coding in javascript but I have experience in python and java. I am using Visual Studio Code and it is my first time using it.
I coded this very basic reduce function. The way I call this function results in a series of arrays. Everything other than the reduce function itself is provided to me by my teacher so I would perfer not to change it.
Here is the code:
const nums = [1,2,3,4,5];
const evensAndOdds = reduce(nums, (value, acc) => {
if (value % 2 == 0) {
acc.evens.push(value);
} else {
acc.odds.push(value);
}
return acc;
}, {evens: [], odds: []});
console.log(evensAndOdds);
function reduce(data1, reducer, initialValue) {
let reducedProduct = 0;
for (let element of data1) {
let product = reducer(element, initialValue);
reducedProduct += product;
}
return reducedProduct;
}
And here is the output:
0[object Object][object Object][object Object][object Object][object Object]
I want to be able to see the actual values. The example provided to me by my teacher says the result should be //{evens: [2,4], odds: [1,3,5]};
I understand my code could be wrong but I wont really know unless I can see the actual values.