3 ms·
const zeroPad = num => ‘00000000’.slice(String(num).length) + num; What a bad way to declare a function. Starting with the word 'function' will make the code m
by codedokode 9y ago
const zeroPad = num => ‘00000000’.slice(String(num).length) + num;
What a bad way to declare a function. Starting with the word 'function' will make the code much more readable. Arrow functions are supposed to be used as a small callbacks, not to obfuscate the meaning of the code.
- jacobolus 9y agoIf you spend a few days reading code written in this style, you will quickly get used to it. This is not “obfuscated”, and there’s nothing wrong with using this syntax for general functions. (Personally, I would recommend putting the function body on the next line, but meh.) If you have any kind of reasonable text editor, you can add syntax highlighting or other visual call-outs for functions, if that is important to you.
- hyper_reality 9y agoI was more confused by the parameter being named 'num' before having the String function called on it and its length taken - when in fact 'num' should be a binary string when it's passed into the function. But maybe I've been spoiled by strong types.
- hodl 9y agoThe rightmost num is coerced. And the hole is finished on par.
- vbezhenar 9y agofunction keyword carries a lot of stuff: this variable, arguments variable, function name can be accidentally changed later. constant lambda is easier to understand.
- hodl 9y agoI'm from Haskell. I love it.