I'm trying to write a function that used reduce() method to count the number of items in an array and return the length of that array.
This is what I have so far:
function len(items) {
items.reduce(function(prev, curr, index){
return index+1;
});
}
let nums = [1, 2, 3];
console.log(len(nums));
Whenever I try to run this code, in the console on my browser I get the message 'undefined'. I think I defined my function properly, so I don't know why its not being called or outputting any values. Please let me know what I'm doing wrong or if my logic is wrong.