当前位置:网站首页>Sort sort
Sort sort
2022-07-27 23:48:00 【yibucuo】
arr.sort() Don't pass parameters , When sorting Pure Strings
var arr = ['a', 'cc', 'ef', 'cb', 'ca', 'ea', 'bc']
arr.sort()
console.log(arr); // ['a', 'bc', 'ca', 'cb', 'cc', 'ea', 'ef']
brr.sort() Don't pass parameters , When excluding pure numbers
var brr = [10, 5, 2, 8, 1, 100, 30, 12, 4, 3]
brr.sort()
console.log(brr);// [1, 10, 100, 12, 2, 3, 30, 4, 5, 8]
crr.sort() Don't pass parameters , Mixed sorting of numbers and strings
var crr = ['a', 10, 'cc', 5, 'ef', 'cb', 2, 'ca', 8, 'ea', 1, 'bc', 100,'a1','c1', 30, 12, 4, 3]
crr.sort()
console.log(crr);// [1, 10, 100, 12, 2, 3, 30, 4, 5, 8, 'a', 'a1', 'bc', 'c1', 'ca', 'cb', 'cc', 'ea', 'ef']
drr.sort((a, b) => a - b)
var drr = [10, 5, 2, 8, 1, 100, 30, 12, 4, 3]
drr.sort((a, b) => a - b)
console.log(drr);// [1, 2, 3, 4, 5, 8, 10, 12, 30, 100]
err.sort((a, b) => a.first_name.localeCompare(b.first_name))
var err = [
{
first_name: 'a', last_name: 'a_a' },
{
first_name: 'cc', last_name: 'cc_cc' },
{
first_name: 'ef', last_name: 'ef_ef' },
{
first_name: 'cb', last_name: 'cb_cb' },
{
first_name: 'ca', last_name: 'ca_ca' },
{
first_name: 'ea', last_name: 'ea_ea' },
{
first_name: 'bc', last_name: 'bc_bc' },
];
err.sort((a, b) => a.first_name.localeCompare(b.first_name))
console.log(err);
[{
…}, {
…}, {
…}, {
…}, {
…}, {
…}, {
…}]
0: {
first_name: 'a', last_name: 'a_a'}
1: {
first_name: 'bc', last_name: 'bc_bc'}
2: {
first_name: 'ca', last_name: 'ca_ca'}
3: {
first_name: 'cb', last_name: 'cb_cb'}
4: {
first_name: 'cc', last_name: 'cc_cc'}
5: {
first_name: 'ea', last_name: 'ea_ea'}
6: {
first_name: 'ef', last_name: 'ef_ef'}
length: 7
The overall code is as follows :
<!DOCTYPE html>
<html lang="en">
<body>
<script> var arr = ['a', 'cc', 'ef', 'cb', 'ca', 'ea', 'bc'] arr.sort() console.log(arr); // ['a', 'bc', 'ca', 'cb', 'cc', 'ea', 'ef'] </script>
<script> var brr = [10, 5, 2, 8, 1, 100, 30, 12, 4, 3] brr.sort() console.log(brr);// [1, 10, 100, 12, 2, 3, 30, 4, 5, 8] </script>
<script> var crr = [10, 5, 2, 8, 1, 100, 30, 12, 4, 3] crr.sort((a, b) => a - b) console.log(crr);// [1, 2, 3, 4, 5, 8, 10, 12, 30, 100] </script>
<script> var drr = [ {
first_name: 'a', last_name: 'a_a' }, {
first_name: 'cc', last_name: 'cc_cc' }, {
first_name: 'ef', last_name: 'ef_ef' }, {
first_name: 'cb', last_name: 'cb_cb' }, {
first_name: 'ca', last_name: 'ca_ca' }, {
first_name: 'ea', last_name: 'ea_ea' }, {
first_name: 'bc', last_name: 'bc_bc' }, ]; drr.sort((a, b) => a.first_name.localeCompare(b.first_name)) console.log(drr);// </script>
</body>
</html>
边栏推荐
- TFRecord的Shuffle、划分和读取
- This is the most concise guide to tcpdump in history. It's enough to read this one
- The txt file named according to the sequence number is renamed from the back to the front
- smartRefresh嵌套多个RecycleView滑动冲突及布局显示不全
- C # delegate usage -- console project, which implements events through delegation
- 进制转换方法
- Date的使用
- Yijia will release ODM orders in 2020 and make efforts in the middle and low-end market
- 详解分布式系统的幂等
- Master data management theory and Practice
猜你喜欢

proteus仿真arduino中调用DHT11/22温湿度传感器

【12月海口】2022年第六届船舶,海洋与海事工程国际会议(NAOME 2022)
![[C language] address book (dynamic version)](/img/29/3df19c187bee31ee4671e12d7cc7ff.jpg)
[C language] address book (dynamic version)

Key points of data management

CaEGCN: Cross-Attention Fusion based Enhanced Graph Convolutional Network for Clustering 2021
![[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters](/img/05/7029eb1fe36d7ddab2640f07247c81.png)
[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters

NDK series (6): let's talk about the way and time to register JNI functions

The technology of applet container is very promising, which can greatly improve the efficiency of mobile R & D

org.junit.runners.model.InvalidTestClassError: Invalid test class ‘com.zhj.esdemo.MysqlTests‘: 1.

J9数字科普:Sui网络的双共识是如何工作的?
随机推荐
详解分布式系统的幂等
Common Taylor expansion
Key points of data management
Record the errors about formatc in R language
Flutter pull_ to_ refresh-1.6.0/lib/src/internals/slivers. dart:164:13: Error: Method not found: ‘descr
Reinforcement learning - pytorch realizes advantage actor critical (A2C)
Redis hash underlying data structure
日产1500万只!比亚迪口罩拿下美国加州10亿美元订单
urllib.error. URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: un
2022/7/24-7/25
RPA流程自动化机器人是什么技术?如何实现办公自动化?
Remotely debug idea, configure remote debug, and add JVM startup parameter -xdebug in the program of remote server
[December Haikou] the 6th International Conference on ships, marine and Maritime Engineering in 2022 (naome 2022)
reduce错误示范
Lua basic grammar learning
Interviewer: let's talk about the specific process of network data transmission
[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters
Shuffle, partition and read of tfrecord
What are the methods of process synchronization?
2022/7/26