Skip to content

Commit

Permalink
sort members by lastname, keep m initial members unsorted
Browse files Browse the repository at this point in the history
  • Loading branch information
shravanngoswamii committed Oct 26, 2024
1 parent 7a0552c commit 2858cef
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions team/team.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
<% items.forEach(item => {
if (item.title === "Team Members") {
// Update this to the number of initial members to keep unsorted
const m = 2;
// Separate the first m members
const firstMembers = item.members.slice(0, m);
const remainingMembers = item.members.slice(m);
// Sort the remaining members by last name
remainingMembers.sort((a, b) => {
const lastNameA = a.name.split(' ').pop().toLowerCase();
const lastNameB = b.name.split(' ').pop().toLowerCase();
return lastNameA.localeCompare(lastNameB);
});
// Recombine the arrays: unsorted first m members + sorted remaining members
item.members = firstMembers.concat(remainingMembers);
} else {
// Sort all members by last name if title is not "Team Members"
item.members.sort((a, b) => {
const lastNameA = a.name.split(' ').pop().toLowerCase();
const lastNameB = b.name.split(' ').pop().toLowerCase();
return lastNameA.localeCompare(lastNameB);
});
}
}); %>

<!-- ::: {.panel-tabset} -->
<% for (const item of items) { %>
Expand Down

0 comments on commit 2858cef

Please sign in to comment.