4 ms·
Type cohersion and type juggling can bring a few surprises. But usually only when you do something weird to hit those edge cases. Otherwise, it's standard libra
by djxfade 3y ago
Type cohersion and type juggling can bring a few surprises. But usually only when you do something weird to hit those edge cases. Otherwise, it's standard library is actually very decent now. Especially when working with arrays. You have all the nice to have methods, like, split, find, filter, map, reduce, every, some, etc... Which makes it a really nice language for these kind of tasks.
The example above would like this in modern javascript:
str.split(',').map(char => Number(char)).filter(num => num > 5).length
- worksonmine 3y agoOr if you like to live dangerously: str.split(',').filter(n => +n > 5).length
- dumbo-octopus 3y agoNot all that dangerous, tbh. My main concern would be NaN potentially cascading through, but not only is `NaN > 5` false, `!!NaN` is too.
- saagarjha 3y agoTo be clear by “standard library” I mean that Python has like actual data structures that are useful. Also while not part of the standard library arbitrary precision integers and associated functions (e.g. modular pow) can be quite helpful.