Почему не происходит сортировка, элементы просто меняются местами при нажатии

всё делала по этому видео https://www.youtube.com/watch?v=eiV1j5qbbCE

вот код

const table = document.querySelector('table');
let colIndex=-1;
const sortTable=function (index,type,isSored) {
    const tbody = table.querySelector('tbody')

    const compare = function (rowA,rowB)
    {
      const rowDataA= rowA.cells[index].innerHTML
      const rowDataB= rowB.cells[index].innerHTML

        switch(type)
        {
          case'integer':
          case'double':
             return rowDataA-rowDataB
            break
          case 'date':
            const dataA =rowDataA.split('.').reverse().join('-')
            const dataB =rowDataA.split('.').reverse().join('-')
            return  new Date(dateA).getTime()-new Date(dateB).getTime()
            break
          case'text':
            if (rowDataA<rowDataB) return -1;
            else  if (rowDataA>rowDataB) return 1;
            return 0
            break
        }

    }
    let rows=[].slice.call(tbody.rows)
    rows.sort(compare)
  if (isSored) rows.reverse()
    table.removeChild(tbody)
    for (let i=0;i<rows.length;i++){
        tbody.appendChild(rows[i])
    }
    table.appendChild(tbody)
}
table.addEventListener('click',(e) => {
    const Datapack=e.target
    if (Datapack.nodeName === 'th') return;

    const index=Datapack.cellIndex
    const type=Datapack.getAttribute('data-type')

    sortTable(index,type,colIndex===index);
    colIndex=(colIndex === index)? -1 : index
});
Вернуться на верх