Open guyuezhai opened 4 years ago
studyDemo = () => { let arr1 = ['A1', 'A2', 'B1', 'B2', 'C1', 'C2', 'D1', 'D2']; let arr2 = ['A', 'B', 'C', 'D']; let arr3 = arr1.concat(arr2); console.log(arr3) let res = arr3.sort((a, b) => { let aaa = a.split(""); let bbb = b.split("") if (aaa[0] > bbb[0]) { return 1; } else if (aaa[0] < bbb[0]) { return -1; } else if (aaa[0] === bbb[0] && aaa[1] && bbb[1] && aaa[1] > bbb[1]) { return 1; } else if (aaa[0] === bbb[0] && aaa[1] && bbb[1] && aaa[1] < bbb[1]) { return -1; } else if (aaa[0] === bbb[0] && !aaa[1]) { return 1; } else if (aaa[0] === bbb[0] && !bbb[1]) { return -1; } else { return 0; } }); console.log(res) }