washingcode-book
washingcode-book copied to clipboard
Fix the isVisible predicates in Avoid mutation section
This change also makes the isVisible predicates equivalent to the predicates in the previous example in this chapter.
I should add a comment about this change but it was intentional: the original solution with +
 is too hacky for me.
Could you clarify, is this expression is too hacky for you?
product1.colors.length + product2.colors.length > 0
Yep. There's no reason to use summ here ;-/
Yep. There's no reason to use summ here ;-/
It seems logical to me, but it's up to you, of course. However, the current version contains a closing bracket in the wrong place:
(product1.colors.length > 0 || product2.colors.length) > 0
vs.
(product1.colors.length > 0 || product2.colors.length > 0)
And that was the original reason why I decided to make the PR.