DEV Community

Discussion on: The Life-Changing Magic of Flat Code

Collapse
 
blindfish3 profile image
Ben Calder

This is a good, succinct description of a useful technique. I would however think about adding some detail of what's happening in that loop. The final code looks like you're just going to return the value from the last iteration; which I'm sure isn't what's intended ;)
Depending on what it does you could even extend the example to directly return the output from an array function (e.g. reduce, map etc.)

Collapse
 
recursivefaults profile image
Ryan Latta

Haha, you're in my head. As I was writing the example I was deciding how far I wanted to carry it for correctness. I opted for keeping the code near the if's at a more abstract level. Partially hoping people wouldn't fixate on it ;)