Array.prototype.reduce是个计算的好手:
考虑两个数组的相似点都有相同是字母开头,可以用双重遍历正则匹配插入也可以用startsWith判断首字母;
const arr1 = ["A1", "A2", "B1", "B2", "C1", "C2"]
const arr2 = ["A", "B", "C"]
arr1.reduce((new, cur) => [...new, ...arr2.filter(item => item.startsWith(cur)), cur], [])
这个是看别人比较新奇的想法:
arr2 = arr2.map(v => `${v}3`)
[...arr1, ...arr2].sort().map(v => v.replace('3', ''))