Skip to content

Commit 17c9ce7

Browse files
committed
Refactor sorting functions to use toSorted
Replaced manual array cloning and sort with the toSorted method in sortByDate and sortByTitle for cleaner and more efficient code.
1 parent fd7bb6d commit 17c9ce7

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/service/database.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ export async function getComponents() {
207207
}
208208

209209
export function sortByDate(dbItems) {
210-
const clonedDbItems = [...dbItems]
211-
212-
return clonedDbItems.sort((itemA, itemB) => {
210+
return dbItems.toSorted((itemA, itemB) => {
213211
const dateA = new Date(itemA.updated)
214212
const dateB = new Date(itemB.updated)
215213

@@ -218,9 +216,7 @@ export function sortByDate(dbItems) {
218216
}
219217

220218
export function sortByTitle(dbItems) {
221-
const clonedDbItems = [...dbItems]
222-
223-
return clonedDbItems.sort((itemA, itemB) => {
219+
return dbItems.toSorted((itemA, itemB) => {
224220
const titleA = itemA.title
225221
const titleB = itemB.title
226222

0 commit comments

Comments
 (0)