Re:Oh, Go Ahead, Overthink FizzBuzz (2008)
by ggurgone on Thursday November 19, 2015 @02:38PM
(#10597007)
sure, what other conditional are you talking about? the for condition?
Re:Oh, Go Ahead, Overthink FizzBuzz (2008)
by adrae5df on Thursday November 19, 2015 @02:42PM
(#10597029)
Second expression in the for loop and ||, both behave as conditionals, i.e. are equivalent to an if statement and the generated instruction will be a branch.
At least it would in C. Of course I'm ignoring the fact that JS is interpreted as will cause a lot of additional bloat, but were not counting that.
Re:Oh, Go Ahead, Overthink FizzBuzz (2008)
by ggurgone on Thursday November 19, 2015 @02:52PM
(#10597097)
No doubt about it. The question was about avoiding the if/else within the for loop body.
In js the for could be replaced with an array of 100 elems and a forEach:
Array.apply(null, { length: 100 }).forEach(function (_, i) { })
Is first expression true? If it isn't evaluate the second expression.