I like to build cool things, work with nice people and help others where I can. Currently I'm an engineering manager for a fintech startup and historically a serial founder & freelancer software dev.
Location
München, Deutschland 🇩🇪
Education
The Open University
Work
Engineering Manager @ Deutsche Fintech Solutions GmbH
This breaks some critical clean code principles, to name a few:
odd_or_even has no block assignment (var, const, let)
The one liner is unnecessary and makes the code harder to read and understand
Duplication of ‘even’ which should be a variable if reused but cannot be in a one line context and doesn’t need to be in a block context as in my version
Using == instead of === for value checks
Don’t get me wrong, this will function fine enough but functioning doesn’t mean its good.
We developers read code far more than we write it and further to that, the industry has more juniors than seniors at any time which makes the readability aspect all the more important. Lastly, proper equality checks and block assignments are essential in languages like JavaScript because global scope pollution can result in overrides and improper equality checks can result in false positives.
late to this but ...
odd_or_even = (arr) => arr.length == 0 ? 'even' : arr.reduce((acc, each) => acc + each) % 2 == 0 ? 'even' : 'odd'
This breaks some critical clean code principles, to name a few:
odd_or_even
has no block assignment (var
,const
,let
)==
instead of===
for value checksDon’t get me wrong, this will function fine enough but functioning doesn’t mean its good.
We developers read code far more than we write it and further to that, the industry has more juniors than seniors at any time which makes the readability aspect all the more important. Lastly, proper equality checks and block assignments are essential in languages like JavaScript because global scope pollution can result in overrides and improper equality checks can result in false positives.
thanks