Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
jeeper59662y@Ranchonyx JS arrays are mutable. So sort sorts the array you call it on. In Java, arrays are immutable. If you sort it, you generally return a copy of the sorted array (more to it but not getting in the Java logic weeds here), the original array is not changed. So you have to assign that sorted array to a variable and work with that to get the sorted data.
However here they have used a Java form of assigning the sort result to a new variable, but continuing to work with the original array variable, so they clearly knew the original array was sorted and the variable was unnecessary. The assignment is useless but they left it in. Sloppy at best, ditzy at worst. Infuriating regardless because I have to look for if they randomly decided to use the other variable anywhere else. And that’s not even getting into the scope issues. -
@jeeper I had a feeling it was something like that.
Shouldn't a linter throw a warning at least?
Related Rants
Reading JS written by “creative” types:
var myArray = []; //un-sorted values
var SortedArray = myArray.sort();
OrderedHtmlElement.innerText = myArray[0];
Look here if you are going to do it wrong at least commit to the wrongdoing!!!
rant
js
coding
array
noncoders
mutable
javascript