题解 | #数组排序#

数组排序

https://www.nowcoder.com/practice/18ea36ef9b0c470e9db7681eced6e8df

function show(arr) {
        arr.map((item) => {
          let oli = document.createElement("li");
          oli.innerText = item.name;
          ul.append(oli);
        });
      }
      show(cups);

      upbtn.onclick = function () {
        cups.sort((a, b) => {
          return a.sales - b.sales;
        });
        ul.innerHTML = "";
        show(cups);
      };
      downbtn.onclick = function () {
        cups.sort((a, b) => {
          return b.sales - a.sales;
        });
        ul.innerHTML = "";
        show(cups);
      };

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务