I am trying to sort an array of s3 buckets based on the creation date (lastest first). I am getting the same array repeated multiple times in the sorted array. I know I am missing something here but am unable to figure out what. My code is:
var bucketListArr = [];
for (var index in data.Buckets) {
var bucket = data.Buckets[index];
//if(bucketList[index] == null) bucketList[index] = [];
bucketListArr.push({
"bucketName": bucket.Name,
"creationDate": bucket.CreationDate
});
// bucketList[index][0] = bucket.Name;
// bucketList[index][1] = bucket.CreationDate;
}
var sortedBucketListArr = [];
//console.log("Bucket List :: ", bucketList, " length :: " , bucketList.length );
for(var i= 0;i < bucketListArr.length; i++){
for(var j = i + 1; j< bucketListArr.length; j++){
if(bucketListArr[i].creationDate >= bucketListArr[j].creationDate){
sortedBucketListArr.push({
"bucketName": bucketListArr[i].bucketName,
"creationDate": bucketListArr[i].creationDate
});
}
}
}
console.log("Sorted List :: ", sortedBucketListArr);
Thanks in advance for any help.