Open EdwardZZZ opened 7 years ago
// 版本比较
const result = arr.sort((str1, str2) => {
let i = 0;
const arr1 = str1.split('.');
const arr2 = str2.split('.');
while (true) {
const s1 = arr1[i];
const s2 = arr2[i++];
if (s1 === undefined || s2 === undefined) {
return arr1.length - arr2.length;
}
if (s1 === s2) continue;
return s1 - s2;
}
});
用js把 aaa?.bbb?.ccc?[45]?.ddd 解析成下面的字符串 aaa && aaa.bbb && aaa.bbb.ccc && aaa.bbb.ccc[45] && aaa.bbb.ccc[45].ddd