桶排序-Node.js-对象排序

const b = [{index:5,name:"s5"}, {index:2,name:"s2"}, {index:3,name:"s3"}, {index:1,name:"s1"}, {index:8,name:"s8"}];
var a = [],
	i;

for (var i = 0; i < b.length; i++) {
	var num = b[i].index;
	a[num] = a[num]||{};
	a[num] = b[i];	
	num == null;
}

for (var i = 0; i < a.length; i++) {
	if(a[i]) console.log(a[i].name);
}

 

posted @ 2016-09-22 16:55  levyleo  阅读(362)  评论(0编辑  收藏  举报