当前位置:网站首页>Sorting method of administrative route code letter + number
Sorting method of administrative route code letter + number
2022-06-30 03:03:00 【Indescribable】
The first one is :
// lxbm: G1,G4,SL3596,H89...
const array = []
array.map(item => {
const tmpArr = item.lxbm.split('')
const reg = /[a-z,A-Z]/g
item.sortLetter = '' // The result of converting letters to numbers
item.sortNum = '' // The result of pure numbers
tmpArr.map(it => {
if (reg.test(it)) {
item.sortLetter += it.charCodeAt(0).toString() // Converting letters into numbers
} else {
item.sortNum += it.toString()
}
})
return item
})
// sort Sort
array.sort((a, b) => {
return this.sortLxbm(a, b)
})
// Sort rule
sortLxbm(a, b) {
// When the letters are the same , Sort by route number
if (Number(a.sortLetter) === Number(b.sortLetter)) {
return Number(a.sortNum) - Number(b.sortNum)
}
// Alphabetical order
return Number(a.sortLetter) - Number(b.sortLetter)
}
The second kind :
// lxbm: G1,G4,SL3596,H89...
// lxmc: Jingha , Jingguang , Jingzang ...
const array = []
const nameArr = []
array.map(item => {
item.lxmcn = item.lxbm + '-' + item.lxmc
nameArr.push(item.lxmcn)
return item
})
nameArr.sort() // Use the spliced name directly sort Sort ,sort Will automatically process the order of letters and numbers ( Maybe the end result is not what you want , At this time, you need to customize and adjust the logic ...)
// The resulting array is then sorted by a specific array of names , Refer to the following :
/** * Arrays are sorted in a specific order * such as : Existing arrays are arranged in the following order : Blizzard 、 Rain and dew 、 The thunder 、 Heavy rains 、 Sandwind 、 Flying fog * The core is to use free sort Method * @param now The current array to be sorted * @param mirror Specified collation */
let now = [' Rain and dew ',' White frost ',' Flying fog ',' Heavy rains ',' Blizzard ',' The thunder ',' Sandwind '];
let mirror = [' Blizzard ',' Rain and dew ',' The thunder ',' Heavy rains ',' Sandwind ',' Flying fog '];
let val = now.sort(function(a, b) {
// Those that don't correspond to the top of the list will go to the back
if (mirror.indexOf(a) == -1 || mirror.indexOf(b) == -1) {
return mirror.indexOf(b) - mirror.indexOf(a);
} else {
return mirror.indexOf(a) - mirror.indexOf(b);
}
})
边栏推荐
- Tri rapide, index groupé, recherche de la plus grande valeur K dans les données
- Wechat applet +php to realize authorized login operation
- HOOK Native API
- C console format code
- Interrupt operation: abortcontroller learning notes
- 自定义JvxeTable的按钮及备注下$set的用法
- What is the metauniverse: where are we, where are we going
- What is the difference between a layer 3 switch and a layer 2 switch
- Jvxetable sub table record loading completion event
- Template parameter package and function parameter package
猜你喜欢

如何在 JupyterLab 中把 ipykernel 切换到不同的 conda 虚拟环境?

福利抽奖 | 开源企业级监控Zabbix6.0都有哪些亮点

Mysql表数据比较大情况下怎么修改添加字段

Raki's notes on reading paper: Leveraging type descriptions for zero shot named entity recognition and classification

公司电脑强制休眠的3种解决方案

Raki's notes on reading paper: named entity recognition as dependency parsing

Visual HTA form designer htamaker interface introduction and usage, Download | HTA VBS visual script writing

Heavy attack -- ue5's open source digital twin solution

uniapp 地址转换经纬度

HTA入门基础教程 | VBS脚本的GUI界面 HTA简明教程 ,附带完整历程及界面美化
随机推荐
Uniapp address translation latitude and longitude
如何实现远程协同办公,收好这份攻略!
MySQL extracts strings from table fields
Xunwei NXP itop-imx6 development platform
炒现货黄金的交易平台如何保障资金安全?
The Oracle main program is deleted, but the data is on another hard disk. Can I import the data again?
CMake教程系列-02-使用cmake代碼生成二進制
什么是外链和内链?
Formal and actual parameters, value passing and address passing
身份证号的严谨判断精确到队后一位
OP-diode-限制摆幅
备忘一下es6的export/import和类继承的用法
2022 tool fitter (Advanced) and tool fitter (Advanced) certificate examination
Call collections Sort() method, compare two person objects (by age ratio first, and by name ratio for the same age), and pass lambda expression as a parameter.
CMake教程系列-04-编译相关函数
prompt learning 一个空格引发的血案
HOOK Native API
Jvxetable增加自定义按钮
Idea remote debugging remote JVM debug
Three solutions to forced hibernation of corporate computers