Skip to content
This repository was archived by the owner on Jul 7, 2025. It is now read-only.

Commit ce6ba33

Browse files
authored
refactor: status order from compare function (#682)
1 parent 063f781 commit ce6ba33

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/rails-status.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,10 @@ const statusOrder = [
1414
* @returns {string | null} latest status if valid, `null` otherwise
1515
*/
1616
export const latestStatusFrom = (statuses) => {
17-
let highestRank = -1
18-
let latestStatus = null
19-
20-
for (const status of statuses) {
21-
const rank = statusOrder.indexOf(status)
22-
23-
if (rank > highestRank) {
24-
highestRank = rank
25-
latestStatus = status
26-
}
27-
}
28-
29-
return latestStatus
17+
return statuses
18+
.filter(status => statusOrder.includes(status))
19+
.sort(compareStatuses)
20+
.at(-1) ?? null
3021
}
3122

3223
/**

0 commit comments

Comments
 (0)