当前位置:网站首页>[sorting of object array]
[sorting of object array]
2022-07-05 09:28:00 【Guodong pudding】
/**
* @desc Sort the array elements according to the specified attributes in the object array
* @param objArr An array of objects to sort
* @param attribute Sort properties
* @param orderFlag Mode identification ,true In the positive order false For reverse order The default is true
* @returns Array after sorting
*/
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));
}
边栏推荐
- Rebuild my 3D world [open source] [serialization-2]
- Wxml template syntax
- Lepton 无损压缩原理及性能分析
- C # image difference comparison: image subtraction (pointer method, high speed)
- Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
- Applet network data request
- C form click event did not respond
- Kotlin introductory notes (V) classes and objects, inheritance, constructors
- Kotlin introductory notes (III) kotlin program logic control (if, when)
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
猜你喜欢

LeetCode 496. 下一个更大元素 I

使用el-upload封装得组件怎么清空已上传附件

NIPS2021 | 超越GraphCL,GNN+对比学习的节点分类新SOTA

nodejs_ 01_ fs. readFile

【数组的中的某个属性的监听】

Kotlin introductory notes (V) classes and objects, inheritance, constructors
![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]

顶会论文看图对比学习(GNN+CL)研究趋势

High performance spark_ Transformation performance

Unity skframework framework (24), avatar controller third person control
随机推荐
【两个对象合并成一个对象】
VS Code问题:长行的长度可通过 “editor.maxTokenizationLineLength“ 进行配置
Talking about label smoothing technology
Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]
.NET服务治理之限流中间件-FireflySoft.RateLimit
Kotlin introductory notes (VIII) collection and traversal
Kotlin introductory notes (VII) data class and singleton class
nodejs_ 01_ fs. readFile
Rebuild my 3D world [open source] [serialization-2]
Generate confrontation network
Composition of applet code
It's too difficult to use. Long articles plus pictures and texts will only be written in short articles in the future
Android privacy sandbox developer preview 3: privacy, security and personalized experience
Ministry of transport and Ministry of Education: widely carry out water traffic safety publicity and drowning prevention safety reminders
LeetCode 31. Next spread
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
C # image difference comparison: image subtraction (pointer method, high speed)
信息与熵,你想知道的都在这里了
Nips2021 | new SOTA for node classification beyond graphcl, gnn+ comparative learning
高性能Spark_transformation性能