Я пытаюсь понять, как работает функция Reduct () в этом примере:
const fruits = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple'];
const count = fruits.reduce((tally, fruit) => {
tally[fruit] = (tally[fruit] || 0) + 1;
return tally;
}, {});
console.log(count);
< /code>
Что означает (tally [fruit] || 0)>
Подробнее здесь: https://stackoverflow.com/questions/797 ... m-an-array
Мобильная версия