AutorÃa | Ultima modificación | Ver Log |
export const sortTableData = ({ tableData, sortKey, reverse }) => {
let sortedData
if (!sortKey) return tableData
sortedData = tableData.sort((a, b) => {
if (typeof a[sortKey] === 'string') {
return a[sortKey].toLowerCase() < b[sortKey].toLowerCase() && -1
}
return a[sortKey] - b[sortKey]
})
if (reverse) return sortedData.reverse()
return sortedData
}