const arr2 = ['', '', '', ''];
I made a function using reduce method that returns the number of element when i put a array and a element into the function as arguments . like below.
function count(array, element) {
return array.reduce((count, value) => {
if (value === element) {
count++;
}
return count;
}, 0);
}
result = count(arr2, '');
console.log(result);
output
2
and it worked well. no problem till here.
but, i wanted to make it shorter using ternary operators.
but it doesn't work.
so i converted it trying my best. like below.
function count(array, element) {
return array.reduce((count, value) => value === element ? count++ : count, 0);
}
result = count(arr2, '');
console.log(result);
output
0
how can i fix it?