Sort method not acting as expected when sorting 2D Array

I am working on a program a algorithm that needs to start at the bottom left most point in a data set. This includes lowest x and y value.

let points = [ [ 16, 24 ], [ 15, 23 ], [ 15, 24 ], [ 20, 30 ] ]
points = points.sort((a, b) => a[0] < b[0]).sort((a,b) => a[1] < b[2])
console.log(points)

I tried implementing the sort method, but nothing seems to happen when I run it. [15,23] should come before all other points.

You aren’t quite using the compare function you are passing into sort correctly. I would read up on how that function works.

1 Like