ca-bootcamp mvc and full CRUDL in vanilla ja
https://tal0311.github.io/ca-mvc-book-store/
- this code is part of the service file. it sorts the book list by the user click event.
- Because the object of a book returns several types of variables. The function first determines what type of variable it is. Then, select the desired sort type.
function getBooksForDisplay() {
if (gSortBy !== 'bookName') {
gBooks.sort((a, b) => a[gSortBy] - b[gSortBy])
}
gBooks.sort((a, b) => (a[gSortBy] < b[gSortBy] ? -1 : 1))
return gBooks
}