11
jeeper
2y

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!!!

Comments
  • 0
    Can't blame 'em
  • 1
    Can someone clear this up to me I haven't the foggiest about JS magic
  • 2
    @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.
  • 0
    @jeeper I had a feeling it was something like that.
    Shouldn't a linter throw a warning at least?
  • 1
    Also var :shudders:
  • 1
    @ElectroArchiver ad tech coming in with the highest quality code 🥲
Add Comment