按特定模式对数组排序

时间:2019-06-23 22:31:56

标签: javascript arrays

我想从以下位置获取阵列

const foo = [
    FOO_BAR_A_READ_SELF,
    FOO_BAR_A_WRITE_SELF,
    FOO_BAR_A,
    FOO_BAR_A_READ_ALL,
    FOO_BAR_A_WRITE_ALL,
    FOO_BAR_B_READ_SELF,
    FOO_BAR_B_WRITE_SELF,
    FOO_BAR_B,
    FOO_BAR_B_READ_ALL,
    FOO_BAR_B_WRITE_ALL
]

const foo = [
    FOO_BAR_A,
    FOO_BAR_A_READ_SELF,
    FOO_BAR_A_WRITE_SELF,
    FOO_BAR_A_READ_ALL,
    FOO_BAR_A_WRITE_ALL,
    FOO_BAR_B,
    FOO_BAR_B_READ_SELF,
    FOO_BAR_B_WRITE_SELF,
    FOO_BAR_B_READ_ALL,
    FOO_BAR_B_WRITE_ALL
]

我试图通过用“ _”来分割长度,但是我从未使用过特定的排序功能。

我只使用desc和asc(return 1> -1)|| (返回-1> 1)

有人可以解释我如何获得想要的结果吗?

2 个答案:

答案 0 :(得分:0)

不确定这是我最好的...

$table->string('image')->default('value');
select citiTable.city, citiTable.type, count(*) as amountOfTimes
from citiTable
group by citiTable.city, citiTable.type

答案 1 :(得分:-1)

您尝试过这个吗?

var arr = [
    'FOO_BAR_A_WRITE_SELF',
    'FOO_BAR_A',
    'FOO_BAR_A_READ_SELF',
    'FOO_BAR_A_READ_ALL',
    'FOO_BAR_A_WRITE_ALL',
    'FOO_BAR_B_READ_SELF',
    'FOO_BAR_B_WRITE_SELF',
    'FOO_BAR_B',
    'FOO_BAR_B_READ_ALL',
    'FOO_BAR_B_WRITE_ALL'
];
var sorted = arr.sort();
console.log(sorted);