gree_leran/pages/intergral/ut/dataTo.js

30 lines
733 B
JavaScript

export const resToList = (res) => {
if (res == null || res == undefined) {
return null;
}
console.log("淑娟转换", res);
let list = res.map(e => {
if (e.extField1 == null) {
e.extField1 = 0;
}
return {
username: e.username || '',
profilePicture: e.profilePicture || '',
score: e.extField1,
}
});
//rt the list by score in descending order
list.sort((a, b) => b.score - a.score);
// Add placeholder objects if the list length is less than 3
while (list.length < 3) {
list.push({
username: '',
profilePicture: '',
score: 0,
});
}
return list;
};