feeling fresher today back on it never gonna stop!
am going though some more reduce stuff and just want some clairty on what || symbol is doing within the reducers
heres one example (it is also used in others ive been going though)
const fruitBasket = ['banana', 'cherry', 'orange', 'apple', 'cherry', 'orange', 'apple', 'banana', 'cherry', 'orange', 'fig' ];
const count = fruitBasket.reduce( (tally, fruit) => {
tally[fruit] = (tally[fruit] || 0) + 1 ; // <<< THIS LINE
return tally;
} , {})
okay so i understand its saying if the fruit does not exist as a key in the object put it there and + 1 what i dont understand is the use of the || like how to think of it. ive only used it as an or operator and it doesnt feel like there is sense in using the word or there (maybe im wrong!) i just want to feel more confitable using it a way to remember to include it if you will.
its saying if fruit doent exist put it there set to zero and plus one
if it does already exist just plus one.
obviosly the || is needed but i dont really know how to explain why its needed to myself.