当前位置:网站首页>【对象数组的排序】
【对象数组的排序】
2022-07-05 09:27:00 【果东布丁】
/**
* @desc 根据对象数组中的指定属性进行数组元素排序
* @param objArr 要进行排序操作的对象数组
* @param attribute 排序属性
* @param orderFlag 方式标识,true 为正序 false 为倒序 默认为 true
* @returns 完成排序后的数组
*/
export function objectArraySortByAtr(objArr, attribute,orderFlag=true) {
function compare(key,sortFlag) {
let sortFlagRes;
if(sortFlag){
sortFlagRes=1;
} else{
sortFlagRes = sortFlag?1:-1;
}
return function(value1, value2) {
const val1 = value1[key];
const val2 = value2[key];
if(val1<val2){
return sortFlagRes*-1;
}
if(val1>val2){
return sortFlagRes*1;
}
return 0;
};
}
return objArr.sort(compare(`${attribute}`,orderFlag));
}
边栏推荐
- C # draw Bezier curve with control points for lattice images and vector graphics
- Ministry of transport and Ministry of Education: widely carry out water traffic safety publicity and drowning prevention safety reminders
- Wechat applet obtains household area information
- 高性能Spark_transformation性能
- A detailed explanation of the general process and the latest research trends of map comparative learning (gnn+cl)
- Jenkins Pipeline 方法(函数)定义及调用
- VS Code问题:长行的长度可通过 “editor.maxTokenizationLineLength“ 进行配置
- MYSQL 对字符串类型排序不生效问题
- 22-07-04 西安 尚好房-项目经验总结(01)
- 2311. Longest binary subsequence less than or equal to K
猜你喜欢

Newton iterative method (solving nonlinear equations)

Understanding rotation matrix R from the perspective of base transformation

Progressive JPEG pictures and related

Can't find the activitymainbinding class? The pit I stepped on when I just learned databinding
![Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]](/img/d8/39020b1ce174299f60b6f278ae0b91.jpg)
Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]

A keepalived high availability accident made me learn it again
![[reading notes] Figure comparative learning gnn+cl](/img/44/2e13d63ef654663852cbccb342b838.png)
[reading notes] Figure comparative learning gnn+cl

fs. Path module

Wxml template syntax

What is a firewall? Explanation of basic knowledge of firewall
随机推荐
Kotlin introductory notes (VII) data class and singleton class
Driver's license physical examination hospital (114-2 hang up the corresponding hospital driver physical examination)
Huber Loss
An article takes you into the world of cookies, sessions, and tokens
OpenGL - Model Loading
Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
MySQL does not take effect in sorting string types
【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
Causes and appropriate analysis of possible errors in seq2seq code of "hands on learning in depth"
[beauty of algebra] solution method of linear equations ax=0
What is a firewall? Explanation of basic knowledge of firewall
Talking about label smoothing technology
Ministry of transport and Ministry of Education: widely carry out water traffic safety publicity and drowning prevention safety reminders
OpenGL - Model Loading
nodejs_ fs. writeFile
Kotlin introductory notes (II) a brief introduction to kotlin functions
Android privacy sandbox developer preview 3: privacy, security and personalized experience
Can't find the activitymainbinding class? The pit I stepped on when I just learned databinding
云计算技术热点
一文详解图对比学习(GNN+CL)的一般流程和最新研究趋势