当前位置:网站首页>Array sorting num ranking merge in ascending order
Array sorting num ranking merge in ascending order
2022-07-05 15:18:00 【Front end cat】
let arr1 = [
{num:'7',name:' Xiaohong 7'},
{num:'6',name:' Small m'},
{num:'5',name:' Small d'},
{num:'4',name:' Small c'},
{num:'3',name:' Small f'},
{num:'2',name:' Small s'},
{num:'1',name:' Small e'},
]
let arr2 = [
{ranking:'1',grade:'10'},
{ranking:'2',grade:'9'},
{ranking:'3',grade:'8'},
{ranking:'7',grade:'4'},
{ranking:'4',grade:'7'},
{ranking:'5',grade:'6'},
{ranking:'6',grade:'5'},
]
// num ranking in ascending order
let arr1Sort = arr1.sort((a,b)=>{
return a.num -b.num
})
let arr2Sort = arr2.sort((a,b)=>{
return a.ranking -b.ranking
})
console.log("arr1Sort ",arr1Sort ,arr2Sort )
let crr = []
arr2Sort.forEach((item, i) => {
console.log(item)
let obj = {
...item,
name: arr1Sort[i].name
}
crr.push(obj)
})
// Will be small c Put it at the end of the array
let cIndex = crr.findIndex(value => value.name.includes(" Small c"))
let c = crr[cIndex]
crr.splice(cIndex, 1)
let name = []
let val = []
crr.forEach((item)=>{
name.push(item.name)
val.push(item.grade)
})
crr.push(c)
console.log(crr)
console.log(c)
边栏推荐
- 当代人的水焦虑:好水究竟在哪里?
- Under the crisis of enterprise development, is digital transformation the future savior of enterprises
- GPS原始坐标转百度地图坐标(纯C代码)
- Huawei Hubble incarnation hard technology IPO harvester
- NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
- 可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
- SQL Server learning notes
- Run faster with go: use golang to serve machine learning
- PHP high concurrency and large traffic solution (PHP interview theory question)
- I collect multiple Oracle tables at the same time. After collecting for a while, I will report that Oracle's OGA memory is exceeded. Have you encountered it?
猜你喜欢

MySQL之CRUD

【数组和进阶指针经典笔试题12道】这些题,满足你对数组和指针的所有幻想,come on !

Drive brushless DC motor based on Ti drv10970

【jvm】运算指令

超越PaLM!北大碩士提出DiVeRSe,全面刷新NLP推理排行榜

Differences between IPv6 and IPv4 three departments including the office of network information technology promote IPv6 scale deployment

Bugku's Eval

Selection and use of bceloss, crossentropyloss, sigmoid, etc. in pytorch classification

Machine learning notes - gray wolf optimization

当代人的水焦虑:好水究竟在哪里?
随机推荐
Severlet learning foundation
Long list optimized virtual scrolling
你童年的快乐,都是被它承包了
社区团购撤城“后遗症”
机器学习笔记 - 灰狼优化
The difference between abstract classes and interfaces in PHP (PHP interview theory question)
Bugku's eyes are not real
Interview shock 62: what are the precautions for group by?
Reconnaissance des caractères easycr
Bugku's Ping
Where is the operation of convertible bond renewal? Is it safer and more reliable to open an account
美团优选管理层变动:老将刘薇调岗,前阿里高管加盟
Your childhood happiness was contracted by it
Fr exercise topic - simple question
Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
ICML 2022 | explore the best architecture and training method of language model
Go learning ----- relevant knowledge of JWT
我想咨询一下,mysql一个事务对于多张表的更新,怎么保证数据一致性的?
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
CODING DevSecOps 助力金融企业跑出数字加速度