Ad
  • Custom User Avatar

    .sort((a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2]);
    Array.prototype.sort accepts a callback to define the sorting behavior.
    This callback is designed to accept arrays as its arguments.
    It first checks the first element of both arrays to see which has precedence. if the result of the operation is a non-zero it returns the result and is sorted based on that element.
    If the result of the operation is 0, it means the 2 values are equal and should then be sorted by the second element.
    The same operation is done on the second element and third element with the exception that it will return 0 if the operation on the third element is 0. In this case both arrays are shallowly equal in the first 3 elements.

  • Custom User Avatar

    This is the first time my code has resembled a Best Practice solution. Though I did not modify a String prototype, the majority of my solution reflects similiar to this. As noted from others I do see areas of optimization.