#programmingtip — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #programmingtip, aggregated by home.social.
-
JavaScript (or V8/Chromium?) Magic:
If you want to sort an array like this:
```
[1, 2, 3].sort((e1, e2) => -1);
```It will result in a reversed ordered array in Chromium (V8) because e1 is actually the second element and e2 is the first element!
The Firefox implementation looks more natural to me, because it orders arguments in the correct order. -
A small #ProgrammingTip: rather than coding complex string parsing routines when working with filepaths. Use existing built-in methods such as :
-
python :
os.path.dirname(myPath) / os.path.basename(myPath) -
java :
Paths.get(myPath).getParent() / getFileName() -
#imagej macro : ` File.getDirectory(myPath) / File.getName(myPath)`
I have seen it in a number of different users that I think it’s worth mentioning ;)
-