当前位置:网站首页>【对象数组的排序】
【对象数组的排序】
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));
}
边栏推荐
- 【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
- Thermometer based on STM32 single chip microcomputer (with face detection)
- Nodemon installation and use
- 植物大战僵尸Scratch
- Unity skframework framework (24), avatar controller third person control
- 太不好用了,长文章加图文,今后只写小短文
- Newton iterative method (solving nonlinear equations)
- np. allclose
- Huber Loss
- 深入浅出PyTorch中的nn.CrossEntropyLoss
猜你喜欢
Applet data attribute method
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
The research trend of map based comparative learning (gnn+cl) in the top paper
Unity skframework framework (XXIII), minimap small map tool
[code practice] [stereo matching series] Classic ad census: (5) scan line optimization
Priority queue (heap)
Blogger article navigation (classified, real-time update, permanent top)
Rebuild my 3D world [open source] [serialization-1]
Shutter uses overlay to realize global pop-up
Hi Fun Summer, play SQL planner with starrocks!
随机推荐
植物大战僵尸Scratch
Shutter uses overlay to realize global pop-up
C # draw Bezier curve with control points for lattice images and vector graphics
Applet (use of NPM package)
Huber Loss
Summary and Reflection on issues related to seq2seq, attention and transformer in hands-on deep learning
MYSQL 对字符串类型排序不生效问题
Nodemon installation and use
Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]
The research trend of map based comparative learning (gnn+cl) in the top paper
Kotlin introductory notes (VIII) collection and traversal
Thermometer based on STM32 single chip microcomputer (with face detection)
利用请求头开发多端应用
Applet global style configuration window
Introduction Guide to stereo vision (7): stereo matching
Nips2021 | new SOTA for node classification beyond graphcl, gnn+ comparative learning
高性能Spark_transformation性能
【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
一篇文章带你走进cookie,session,Token的世界
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]