当前位置:网站首页>String sort
String sort
2022-07-24 09:41:00 【Dream height 1.8 meters】
1 array.sort()
Array comes with sort, Sort according to string rules
console.log([5,4,3,2,11].sort()) // 11,2,3,4,5
console.log(["5","4","3","2","11"].sort()) // 11,2,3,4,5
console.log(["5 5、 ... and ","4 Four ","3 3、 ... and ","2 Two ","11 One "].sort()) // 11 One ,2 Two ,3 3、 ... and ,4 Four ,5 5、 ... and
console.log([" 5、 ... and "," Four "," 3、 ... and "," Two "," One "].sort())// One , Two , 3、 ... and , Four , 5、 ... and
2 All numeric sort
console.log([5,4,3,2,11].sort((a, b) => a-b)) // 2,3,4,5,11
console.log(["5","4","3","2","11"].sort((a, b) => a-b)) // 2,3,4,5,11
console.log(["5 5、 ... and ","4 Four ","3 3、 ... and ","2 Two ","11 One "].sort((a, b) => a-b)) // 5 5、 ... and ,4 Four ,3 3、 ... and ,2 Two ,11 One
console.log([" 5、 ... and "," Four "," 3、 ... and "," Two "," One "].sort((a, b) => a-b))// 5、 ... and , Four , 3、 ... and , Two , One
3 Sort according to the number in the string
such as 1 class ,2 class ,……
const arr = ['5 class ', '4 class ', '3 class ', '2 class ', '11 class ']
// With numbers in front , Non numeric after
console.log(arr.sort((a, b) => parseFloat(a) - parseFloat(b))) // 2 class ,3 class ,4 class ,5 class ,11 class
// A string containing only one integer value , Use regular expressions directly to delete the characters of numbers
console.log(arr.sort((a, b) => a.replace(/[^\d]/g,' ') - b.replace(/[^\d]/g,' ')))
边栏推荐
- [Luogu p5829] [template] mismatch tree (string) (KMP)
- Friends come to interview a unicorn company in Beijing at leisure. The interview question is priced at 25K
- Account 1-2
- CUDA day 2: GPU core and Sm core components [easy to understand]
- Nuggets manufacturing industry, digital commerce cloud supply chain collaborative management system to achieve full chain intelligent management and control
- 《动手学深度学习》(七) -- 边界框和锚框
- Boundless dialogue | participate in the live broadcast on July 25 and win the prize
- An article takes you to understand the operation of C language files in simple terms
- Aruba learning notes 06 wireless control AC basic configuration (CLI)
- Huawei wireless device security policy configuration command
猜你喜欢

C#/VB. Net: convert word or EXCEL documents to text

It is reported that the prices of some Intel FPGA chip products have increased by up to 20%

Recursion - if the function calls itself internally, then the function is a recursive function & the effect is the same as that of the loop & the push condition return should be added, otherwise stack

An article takes you to understand the operation of C language files in simple terms
![[MySQL] - deep understanding of index](/img/a6/6ca1356fe11bd33ec7362ce7cdc652.png)
[MySQL] - deep understanding of index

ASI-20220222-Implicit PendingIntent

DP longest common subsequence detailed version (LCS)

What is the component customization event we are talking about?

Opencv learning Day5

Gnuplot software learning notes
随机推荐
Re6: reading paper licin: a heterogeneous graph based approach for automatic legal stat identification fro
[don't bother to strengthen learning] video notes (IV) 1. What is dqn?
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
Spark Learning: a form of association in a distributed environment?
Spark Learning: using RDD API to implement inverted index
A null pointer exception is reported when the wrapper class inserts into the empty field of the database table
S2b2b system standardizes the ordering and purchasing process and upgrades the supply chain system of household building materials industry
What does CRM mean? Three "key points" for CRM management software selection
Onpropertychange property
Spark Learning: build SQL to meet the specified optimization rules
Gnuplot software learning notes
Leetcode question brushing series -- 174. Dungeon games
Es document CRUD
获取所有股票历史行情数据
gnuplot软件学习笔记
Color recognition of regions of interest in pictures and videos based on OpenCV
缓冲区的概念真的理解么?带你揭开缓冲区的面纱~
Es search summary
What are the 6% annualized products?
Vscode failed to use SSH Remote Connection (and a collection of other problems)