3 ms·
It is. Apart from ++index, this is literally the same as: let ch = if index < strlen then str.charAt(index) else 0 Eminently readable and less boring than l
by ghanrt 6y ago
It is. Apart from ++index, this is literally the same as:
let ch = if index < strlen then str.charAt(index) else 0
Eminently readable and less boring than long if/else chains in Python.
- deleted 6y ago[deleted]
- Twirrim 6y agoYou can write in a very similar way in python too if you want to. I think I'd argue this is cleaner syntax, even. >>> foo = 10 >>> bar = foo if foo > 5 else 0 >>> bar 10 >>> bar = foo if foo < 5 else 0 >>> bar 0
- dmos62 6y agoIt's not. To be easily human-parsable you want to do one thing at a time. It's that incrementation that you've ommited that messes things up. On a side note, having gotten used to newer languages, an option type sure is a nice thing.
- jldugger 6y agoIDK, "for ch in index:" reads pretty cleanly to me.