I saw a lot of code like this:
It’s test ternaire I know that.
But first the test don’t have parenteses(why not), but then the sign = assign a variable then compare it?
Can you explain better? counts[item] = counts[item] >= 1 ? counts[item] + 1 : 1;
EDIT
It’a possible this is similar ?
var cts = counts[item] = counts[item];
(cts >= 1) ? counts[item] + 1 : 1;
EDIT 2
it’a more: counts[item] = (counts[item] >= 1) ? counts[item] + 1 : 1;
It’s messy without the parenteses
I hate when I saw a code like this and uncomment…
I was reading left to right and break on this.
Best to read it like this: counts[item] = (counts[item] >= 1 ? counts[item] + 1 : 1);
It checks if counts[item] is bigger than or equal to 1. If it is, increment counts[item] by 1. If it isn’t, set counts[item] to 1.
You could also write it like this: