3 ms·
I was expecting the answer to look something like: products.forEach((p) => p.highlighted = ( /mountain/.test(p.name) || (p.stock > 100 &&
by dan-robertson 7y ago
I was expecting the answer to look something like:
products.forEach((p) =>
p.highlighted = (
/mountain/.test(p.name)
|| (p.stock > 100 && p.price < 5)
|| (p.category == 'outdoors' && 20 < p.price && p.price < 35)))
And if one wants the (implicitly hidden) behaviour that highlighted products stay highlighted forever, just add the condition p.highlighted to the disjunction above.
- dhbradshaw 7y agoWant a job? ;-D
- deaddodo 7y agoforEach is a loop, so this doesn't answer the basic question OP presented.
- dan-robertson 7y agoThe standard doesn’t specify whether or not forEach is a “loop” or not. One could implement it using tail recursion. FWIW I would claim that such recursion should also be called a loop, because the control flow goes in a loop.
- deaddodo 7y agoYou're splitting hairs. I think we can both agree that no implementation does it as such. And if you're going to go to that low of a level, there's no such thing as a loop beyond emergent behavior (they're all conditional branches/jumps).