我有一个对象,它有一个名为 z 的属性:
function building(z)
{
this.z = z;
}
假设我创建了这个对象的 3 个实例:
a = new building(5)
b = new building(2)
c = new building(8)
然后将这些实例放入一个数组中
buildings = []
buildings.push(a)
buildings.push(b)
buildings.push(c)
问题
我将如何根据它包含的对象的z属性按升序对该数组进行排序?排序后的最终结果应该是:
before -> buildings = [a, b, c]
sort - > buildings.sort(fu)
after -> buildings = [b, a, c]