Trying to implement a sorting function with an arrow button that inverts for exam scores
Struggling to get the correct sorting order
The current code snippet results in
[N/A, N/A, 99%, 90%, ... 20%, 100%, 10%, 0%]
being sorted as
[0%, 10%, 100%, 20%, ... 90%, 99%, N/A, N/A]
and vice versa
// Score Sort
if(this.scoreSort && this.sortColumn === 'Score'){
const sortedData = data.sort((a, b) => {
const titleA = a.Score ? a.Score : '';
const titleB = b.Score ? b.Score : '';
if(titleA > titleB){ return this.scoreSort ? 1 : -1 }
if(titleA < titleB){ return this.scoreSort ? -1 : 1 }
return 0;
});
return sortedData;
} if(!this.scoreSort && this.sortColumn === 'Score') {
const sortedData = data.sort((a, b) => {
const titleA = a.Score ? a.Score : '';
const titleB = b.Score ? b.Score : '';
if(titleA > titleB){ return this.scoreSort ? 1 : -1 }
if(titleA < titleB){ return this.scoreSort ? -1 : 1 }
return 0;
});
return sortedData;
}
Is there a way to sort them like the array below?
[100%, 99%, 90%, ... 20%, 10%, 0%, N/A, N/A]
to be displayed as
[0%, 10%, 20%, ... 90%, 99%, 100%, N/A, N/A]
and vice versa