I wrote the following code which works for cases with the array has more than one element. How could I make it work when the array consist of just one element?
The below works for [1,23,4,5] but not for [0], [2], 1
function oddOrEven(array) {
var sum = array.reduce(function(acc, intialvalue) {
return acc + intialvalue;
});
if (sum % 2 == 0) {
return "even"
} else {
return "odd"
}
}
console.log(oddOrEven([1,23,4,5]))
console.log(oddOrEven([0]))
console.log(oddOrEven([1]))

[0], [2], [1]are returning as expected[0], [2], [1]incorrectly?function oddOrEven(array) { var sum = array.reduce((acc, intialvalue) => acc + intialvalue); return (sum % 2 == 0) ? "even" : "odd" }console.log(oddOrEven(1))