fork download
  1. function mySort(type, sortFunc) {
  2.  
  3. var types = ['number', 'name']
  4. type = types.indexOf(type)
  5.  
  6. var trs = document.querySelectorAll('table tbody tr')
  7. var cols = types.map((_, i) => trs.map(tr => tr.querySelectorAll('td')[i]))
  8. var rows = trs.map(tr => tr.querySelectorAll('td'))
  9. var texts = rows.map(tds => tds.map(td => td.textContent))
  10.  
  11. function observer(recs) {
  12. recs.forEach(rec => cols.forEach((tds, i) => tds[rec.name].textContent = texts[rec.name][i]))
  13. }
  14.  
  15. Object.observe(texts, observer)
  16.  
  17. texts.sort((a, b) => {
  18. Object.deliverChangeRecords(observer)
  19. return sortFunc(a[type], b[type]))
  20. }
  21.  
  22. }
  23.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty