https://leetcode.com/problems/container-with-most-water/
More efficient code exists. This problem doesn't need sorting.
var maxArea = function (height) {
let hxs = height
.map((v, x) => [v, x])
.sort(([va, xa], [vb, xb]) => (va === vb ? xa - xb : vb - va));
let left, right;
left = right = hxs.shift()[1];
let max = 0;
for (let [h, x] of hxs) {
let lw = Math.abs(x - left);
let rw = Math.abs(x - right);
let w = Math.max(lw, rw);
max = Math.max(w * h, max);
left = Math.min(x, left);
right = Math.max(x, right);
}
return max;
};