当前位置:网站首页>[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));
}
边栏推荐
- Kotlin introductory notes (I) kotlin variables and non variables
- Wxml template syntax
- Unity skframework framework (XXII), runtime console runtime debugging tool
- SQL learning - case when then else
- OpenGL - Coordinate Systems
- C language - input array two-dimensional array a from the keyboard, and put 3 in a × 5. The elements in the third column of the matrix are moved to the left to the 0 column, and the element rows in ea
- Composition of applet code
- 信息与熵,你想知道的都在这里了
- 【ManageEngine】如何利用好OpManager的报表功能
- Applet global style configuration window
猜你喜欢
Unity SKFramework框架(二十二)、Runtime Console 运行时调试工具
【ManageEngine】如何利用好OpManager的报表功能
LeetCode 496. Next larger element I
Deep understanding of C language pointer
[reading notes] Figure comparative learning gnn+cl
LeetCode 556. Next bigger element III
C语言-从键盘输入数组二维数组a,将a中3×5矩阵中第3列的元素左移到第0列,第3列以后的每列元素行依次左移,原来左边的各列依次绕到右边
Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]
图神经网络+对比学习,下一步去哪?
【数组的中的某个属性的监听】
随机推荐
Jenkins pipeline method (function) definition and call
Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]
2309. The best English letters with both upper and lower case
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
Global configuration tabbar
MYSQL 对字符串类型排序不生效问题
Applet network data request
Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]
Transfer learning and domain adaptation
nodejs_ 01_ fs. readFile
notepad++
【sourceTree配置SSH及使用】
C form click event did not respond
Generate confrontation network
[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b
Thermometer based on STM32 single chip microcomputer (with face detection)
Principle and performance analysis of lepton lossless compression
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
Unity SKFramework框架(二十四)、Avatar Controller 第三人称控制
【el-table如何禁用】