Each item in the array in on the stage, each with an x/y position. The item in the top left most position should be items[0]. X should be the primary.

Originally I was thinking along the lines of:
var items = [m1, m2, m3, m4, m5, m6];
items.sort(sortMe);
function sortMe(a, b)
{
return (b.position[0] - a.position[0]) && (b.position[1] - a.position[1]);
}
But this does not yield the correct results.
sort()should return either0or a negative/positive number.This sorts with
Xtaking precedence:This with
Ytaking precedence (the “natural” order):Which means you just need to replace your
&&with||: