3 ms·
To me this is a code smell, the function would be better off being a named function like getStatusString(n) function getStatusString(n) { if(isPrime(
by gitgud 8y ago
To me this is a code smell, the function would be better off being a named function like getStatusString(n)
function getStatusString(n) {
if(isPrime(n)) {
return 'prime';
}
if(isOdd(n)) {
return 'odd';
}
return 'even';
}
Much easier to read, understand and maintain than an inline monster. No need to add complicated new language constructs for simple situations.....
- seniorsassycat 8y agoI agree, these are contrived examples, but I know that I have reached for inline logic many times in my career. To me another code smell is a scope with too many variables and do expressions are a tool to reduce the scope of variables. Refactoring to named functions will introduce another named variables. Javascript doesn't have private modules so moving logic to helper functions in util modules doesn't reduce scope bloat.