一部对所有不同背景的观众都有娱乐性的节日电影。它将经受时间的考验,以促进一个坚持多样性价值观的时代。在充满回音室和推特暴徒的充满敌意的文化中,经验的多样性可以让所有人团结起来,结束仇恨。一部能带来进入新十年的公开对话的电影。这部电影会很棒的。
发布于 2019-12-06 09:51:13
您可以先按priority_level进行分组,然后根据检查进行排序,如果priority_level以数字开头,则按priority_date进行排序。
const
hasNumber = s => /^\d+/.test(s),
input = [{ priority_level: 'P ', priority_date: '1980-02-08T00:00:00.000Z' }, { priority_level: '1 ', priority_date: '2004-06-29T00:00:00.000Z' }, { priority_level: 'C ', priority_date: '2004-06-29T00:00:00.000Z' }, { priority_level: '5 ', priority_date: '2005-02-15T00:00:00.000Z' }, { priority_level: '1 ', priority_date: '2005-02-15T00:00:00.000Z' }, { priority_level: '1 ', priority_date: '2005-02-15T00:00:00.000Z' }],
result = [...input
.reduce((m, o) => m.set(o.priority_level, [...(m.get(o.priority_level) || []), o]), new Map)
.values()
].flat();
result.sort((a, b) =>
hasNumber(a.priority_level) - hasNumber(b.priority_level) ||
a.priority_date > b.priority_date || -(a.priority_date < b.priority_date)
);
console.log(result);.as-console-wrapper { max-height: 100% !important; top: 0; }
带房客
const
hasNumber = s => /^\d+/.test(s),
input = [{ priority_level: 'P ', priority_date: '1980-02-08T00:00:00.000Z' }, { priority_level: '1 ', priority_date: '2004-06-29T00:00:00.000Z' }, { priority_level: 'C ', priority_date: '2004-06-29T00:00:00.000Z' }, { priority_level: '5 ', priority_date: '2005-02-15T00:00:00.000Z' }, { priority_level: '1 ', priority_date: '2005-02-15T00:00:00.000Z' }, { priority_level: '1 ', priority_date: '2005-02-15T00:00:00.000Z' }],
result = _(input)
.groupBy('priority_level')
.map(array => array)
.flatten()
.sortBy([
o => hasNumber(o.priority_level),
'priority_date'
])
.values();
console.log(result);.as-console-wrapper { max-height: 100% !important; top: 0; }<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
发布于 2019-12-06 09:45:12
const input = [{
priority_level: 'P ',
comments: '',
withdraw_granted_conditions: 'false',
condition: '',
_id: '5db00ad95399ab5cad9e6d44',
company: '5db00a135399ab5cad9e0049',
priority_date: '1980-02-08T00:00:00.000Z',
registration_type: '5db00a125399ab5cad9dfe4b',
sequence: 6835,
waiver_request: false,
waiver_granted: false,
waiver_letter_date: null,
letter_date: null,
waiver_sent: null,
no_extention_letter: false,
mpaa_extention_granted: false
},
{
priority_level: '1 ',
comments: '',
withdraw_granted_conditions: 'false',
condition: '',
_id: '5db00ad95399ab5cad9e6d43',
company: '5db00a145399ab5cad9e0096',
priority_date: '2004-06-29T00:00:00.000Z',
registration_type: '5db00a125399ab5cad9dfe4a',
sequence: 13505,
waiver_request: false,
waiver_granted: false,
waiver_letter_date: null,
letter_date: null,
waiver_sent: null,
no_extention_letter: false,
mpaa_extention_granted: false
},
{
priority_level: 'C ',
comments: '',
withdraw_granted_conditions: 'false',
condition: '',
_id: '5db00ad95399ab5cad9e6d42',
company: '5db00a135399ab5cad9dff5c',
priority_date: '2004-06-29T00:00:00.000Z',
registration_type: '5db00a125399ab5cad9dfe4a',
sequence: 13506,
waiver_request: false,
waiver_granted: false,
waiver_letter_date: null,
letter_date: null,
waiver_sent: null,
no_extention_letter: false,
mpaa_extention_granted: false
},
{
priority_level: '5 ',
comments: '',
withdraw_granted_conditions: 'false',
condition: '',
_id: '5db00ad95399ab5cad9e6d41',
company: '5db00a135399ab5cad9dff5a',
priority_date: '2005-02-15T00:00:00.000Z',
registration_type: '5db00a125399ab5cad9dfe4a',
sequence: 13508,
waiver_request: false,
waiver_granted: false,
waiver_letter_date: null,
letter_date: null,
waiver_sent: null,
no_extention_letter: false,
mpaa_extention_granted: false
},
{
priority_level: '1 ',
comments: '',
withdraw_granted_conditions: 'false',
condition: '',
_id: '5db00ad95399ab5cad9e6d41',
company: '5db00a135399ab5cad9dff5a',
priority_date: '2005-02-15T00:00:00.000Z',
registration_type: '5db00a125399ab5cad9dfe4a',
sequence: 13508,
waiver_request: false,
waiver_granted: false,
waiver_letter_date: null,
letter_date: null,
waiver_sent: null,
no_extention_letter: false,
mpaa_extention_granted: false
}]
const result = input.sort((a, b) => {
const isIntegerA = Number.isInteger(Number.parseInt(a.priority_level));
const isIntegerB = Number.isInteger(Number.parseInt(b.priority_level));
if (a.priority_level < b.priority_level) {
if (isIntegerA & !isIntegerB) {
return 1;
}
return -1;
}
if (a.priority_level > b.priority_level) {
if (!isIntegerA & isIntegerB) {
return -1;
}
return 1;
}
return Date.parse(a.priority_date) - Date.parse(b.priority_date)
});
console.log(result);
const result = input.sort((a, b) => {
const isIntegerA = Number.isInteger(Number.parseInt(a.priority_level));
const isIntegerB = Number.isInteger(Number.parseInt(b.priority_level));
if (a.priority_level < b.priority_level) {
if (isIntegerA & !isIntegerB) {
return 1;
}
return -1;
}
if (a.priority_level > b.priority_level) {
if (!isIntegerA & isIntegerB) {
return -1;
}
return 1;
}
return Date.parse(a.priority_date) - Date.parse(b.priority_date)});发布于 2019-12-06 09:47:19
您可以编写自己的排序逻辑。
const input = [{
priority_level: 'P ',
comments: '',
withdraw_granted_conditions: 'false',
condition: '',
_id: '5db00ad95399ab5cad9e6d44',
company: '5db00a135399ab5cad9e0049',
priority_date: '1980-02-08T00:00:00.000Z',
registration_type: '5db00a125399ab5cad9dfe4b',
sequence: 6835,
waiver_request: false,
waiver_granted: false,
waiver_letter_date: null,
letter_date: null,
waiver_sent: null,
no_extention_letter: false,
mpaa_extention_granted: false
},
{
priority_level: '1 ',
comments: '',
withdraw_granted_conditions: 'false',
condition: '',
_id: '5db00ad95399ab5cad9e6d43',
company: '5db00a145399ab5cad9e0096',
priority_date: '2004-06-29T00:00:00.000Z',
registration_type: '5db00a125399ab5cad9dfe4a',
sequence: 13505,
waiver_request: false,
waiver_granted: false,
waiver_letter_date: null,
letter_date: null,
waiver_sent: null,
no_extention_letter: false,
mpaa_extention_granted: false
},
{
priority_level: 'C ',
comments: '',
withdraw_granted_conditions: 'false',
condition: '',
_id: '5db00ad95399ab5cad9e6d42',
company: '5db00a135399ab5cad9dff5c',
priority_date: '2004-06-29T00:00:00.000Z',
registration_type: '5db00a125399ab5cad9dfe4a',
sequence: 13506,
waiver_request: false,
waiver_granted: false,
waiver_letter_date: null,
letter_date: null,
waiver_sent: null,
no_extention_letter: false,
mpaa_extention_granted: false
},
{
priority_level: '5 ',
comments: '',
withdraw_granted_conditions: 'false',
condition: '',
_id: '5db00ad95399ab5cad9e6d41',
company: '5db00a135399ab5cad9dff5a',
priority_date: '2005-02-15T00:00:00.000Z',
registration_type: '5db00a125399ab5cad9dfe4a',
sequence: 13508,
waiver_request: false,
waiver_granted: false,
waiver_letter_date: null,
letter_date: null,
waiver_sent: null,
no_extention_letter: false,
mpaa_extention_granted: false
},
{
priority_level: '1 ',
comments: '',
withdraw_granted_conditions: 'false',
condition: '',
_id: '5db00ad95399ab5cad9e6d41',
company: '5db00a135399ab5cad9dff5a',
priority_date: '2005-02-15T00:00:00.000Z',
registration_type: '5db00a125399ab5cad9dfe4a',
sequence: 13508,
waiver_request: false,
waiver_granted: false,
waiver_letter_date: null,
letter_date: null,
waiver_sent: null,
no_extention_letter: false,
mpaa_extention_granted: false
}]
input.sort((a, b) => {
if (a.priority_level.trim().match(/[A-Z]/)) {
if (b.priority_level.trim().match(/[A-Z]/)) {
return new Date(a.priority_date) - new Date(b.priority_date);
} return -1;
}
else if (b.priority_level.trim().match(/[A-Z]/)) {
return 1;
}
return new Date(a.priority_date) - new Date(b.priority_date) || (a.priority_level - b.priority_level)
})
console.log(input.map(e => e.priority_level + e.priority_date))
https://stackoverflow.com/questions/59210028
复制相似问题