Last active
September 28, 2018 07:48
Sort guests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
const getLastName = guest => { | |
const title = guest.querySelector('.title-nom-prenom'); | |
const names = title.textContent.split(' '); | |
return names[names.length - 1]; | |
} | |
const isotope = document.querySelector('#isotope-list-invites'); | |
const guests = Array.prototype.slice.call(isotope.querySelectorAll('a')); | |
guests.sort((a, b) => { | |
const aLastName = getLastName(a); | |
const bLastName = getLastName(b); | |
if (aLastName > bLastName) return 1; | |
if (bLastName < aLastName) return -1; | |
return 0; | |
}); | |
isotope.innerHTML = ''; | |
isotope.appendChild(guests[0]); | |
})(); | |
//guests.forEach(guest => guest.remove()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment