题解 | #数组排序#
数组排序
https://www.nowcoder.com/practice/18ea36ef9b0c470e9db7681eced6e8df
优雅
function updata(data) { ul.innerHTML = '' let frg = document.createDocumentFragment() data.forEach((item, index) => { let liEl = document.createElement('li') liEl.innerHTML = item.name frg.append(liEl) }) ul.append(frg) } updata(cups) let salesSortArr = [data => data.sort((r1, r2) => r1.sales - r2.sales), data => data.sort((r1, r2) => r2.sales - r1.sales)] upbtn.onclick = function () { let newData = salesSortArr[0](cups) updata(newData) } downbtn.onclick = function () { let newData = salesSortArr[1](cups) updata(newData) }