gree_leran/pages/intergral/ut/dataTo.js

30 lines
733 B
JavaScript
Raw Normal View History

2024-06-20 15:36:19 +00:00
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;
};