title: Problem with sorting an array more than once... only on Firefox for Ubuntu?
body: <p>This is a semi-complicated question so bear with me for a minute. I've been doing a month long project with the goal being to understand JavaScript. Part of this has been doing Wes Bos' Javascript 30 challenge. Day 4 of the challenge involves using map, sort, and reduce on arrays. By the fact that this is happening on specifically Firefox for Ubuntu, I'll try to just explain the code as best as I can. For those who are curious/have this version of Firefox, the code for this project is on <a href="https://github.com/wesbos/JavaScript30/blob/master/04%20-%20Array%20Cardio%20Day%201/index-FINISHED.html" rel="nofollow noreferrer">Wes' GitHub here</a>.</p>
  
  <p>I'm going to explain this in chronological order. This concerns the code for Wes' solution. By the way, this code isn't exactly wrong. It works on chrome, on basically every browser I've tried on windows, but not for Firefox for Ubuntu. </p>
  
  <p>Right off the bat, something is weird. The array we're working with is defined like this:</p>
  
  <pre><code>const inventors = [
    { first: 'Albert', last: 'Einstein', year: 1879, passed: 1955 },
    { first: 'Isaac', last: 'Newton', year: 1643, passed: 1727 },
    { first: 'Galileo', last: 'Galilei', year: 1564, passed: 1642 },
    { first: 'Marie', last: 'Curie', year: 1867, passed: 1934 },
    { first: 'Johannes', last: 'Kepler', year: 1571, passed: 1630 },
    { first: 'Nicolaus', last: 'Copernicus', year: 1473, passed: 1543 },
    { first: 'Max', last: 'Planck', year: 1858, passed: 1947 },
    { first: 'Katherine', last: 'Blodgett', year: 1898, passed: 1979 },
    { first: 'Ada', last: 'Lovelace', year: 1815, passed: 1852 },
    { first: 'Sarah E.', last: 'Goode', year: 1855, passed: 1905 },
    { first: 'Lise', last: 'Meitner', year: 1878, passed: 1968 },
    { first: 'Hanna', last: 'Hammarström', year: 1829, passed: 1909 }
  ];
  </code></pre>
  
  <p>You would expect this to be represented in the console like this, right? Nope. Every instance of any array based off of this one shows up like this in the console (it left out the last variable but it's not really necessary):</p>
  
  <pre><code>0: Object { first: "Lise", last: "Meitner", year: 1878, … }
  1: Object { first: "Max", last: "Planck", year: 1858, … }
  2: Object { first: "Isaac", last: "Newton", year: 1643, … }
  3: Object { first: "Katherine", last: "Blodgett", year: 1898, … }
  4: Object { first: "Hanna", last: "Hammarström", year: 1829, … }
  5: Object { first: "Galileo", last: "Galilei", year: 1564, … }
  6: Object { first: "Albert", last: "Einstein", year: 1879, … }
  7: Object { first: "Nicolaus", last: "Copernicus", year: 1473, … }
  8: Object { first: "Marie", last: "Curie", year: 1867, … }
  9: Object { first: "Johannes", last: "Kepler", year: 1571, … }
  10: Object { first: "Sarah E.", last: "Goode", year: 1855, … }
  11: Object { first: "Ada", last: "Lovelace", year: 1815, … }
  </code></pre>
  
  <p>This includes the very first time that console.table is called. As it turns out, this is the inventors sorted in decreasing order of length of life. That's defined like this:</p>
  
  <pre><code>const oldest = inventors.sort(function(a, b) {
    const lastInventor = a.passed - a.year;
    const nextInventor = b.passed - b.year;
    return lastInventor &gt; nextInventor ? -1 : 1;
  });
  </code></pre>
  
  <p>This isn't how I would go about this, but that's not the problem. I would check for equality because that should be handled by returning 0. Regardless, I commented this chunk of code out and everything looked fine. </p>
  
  <p>What I think is happening is that Javascript executes the sort by length of life and then... only on Firefox for Ubuntu, 71.0, the most recent version (as of this post)... it makes everything related to that array fixed to that sort. I'm not sure if that's exactly what's going on.</p>
  
  <p>My solution for this was to call inventors.slice().sort at every instance where we just had inventors.sort. Now the whole solution works just fine on Ubuntu. That said, why is this happening? It's not that the arrays are all const, that changes nothing. My understanding is that the JavaScript array sort only rearranges things, but it seems like beyond the first rearranging, it fixes the values of the array and any reference to it. There really shouldn't be a problem with sorting an array twice.</p>
  
  <p>My question is, why is this behavior happening? Is it wrong to sort an array more than twice in JS?</p>