export function sortLikeWin (v1, v2) {
function commonCompare (v1, v2) {
if (v1 === v2) {
return 0
} else {
return v1 < v2 ? -1 : 1
}
}
var a = v1.name
var b = v2.name
var reg = /[0-9]+/g
var lista = a.match(reg)
var listb = b.match(reg)
if (!lista || !listb) {
return commonCompare(a, b)
}
for (var i = 0, minLen = Math.min(lista.length, listb.length); i < minLen; i++) {
var indexa = a.indexOf(lista[i])
var indexb = b.indexOf(listb[i])
var prefixa = a.substring(0, indexa)
var prefixb = b.substring(0, indexb)
var stra = lista[i]
var strb = listb[i]
var numa = parseInt(stra)
var numb = parseInt(strb)
if (indexa != indexb || prefixa != prefixb) {
return commonCompare(a, b)
} else {
if (stra === strb) {
if (i == minLen - 1) {
return a.substring(indexa).localeCompare(b.substring(indexb))
}
else {
a = a.substring(indexa + stra.length)
b = b.substring(indexa + stra.length)
}
}
else if (numa == numb) {
return strb.lastIndexOf(numb + '') - stra.lastIndexOf(numa + '')
} else {
return numa - numb
}
}
}
}