Discuss / JavaScript / 优雅(

优雅(

Topic source
      let list = document.querySelector('#test-list')
      Array.from(list.children)
        .map((e, i) => ({
          index: i,
          value: e.innerText,
        }))
        .sort((x, y) => +(x.value > y.value) || +(x.value === y.value) - 1)
        .map(e => list.children[e.index])
        .forEach(e => {
          list.appendChild(e)
        })

  • 1

Reply