Created
August 23, 2021 18:58
-
-
Save paulgrammer/6818238c51e0d15d67488dcf54fc1699 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 sortArray(values) { | |
return values.sort(function (a, b) { | |
let authorChuckedA = a.author.split(" "); | |
let authorChuckedB = b.author.split(" "); | |
let lastNameA = authorChuckedA[authorChuckedA.length - 1]; | |
let lastNameB = authorChuckedB[authorChuckedB.length - 1]; | |
return lastNameA.localeCompare(lastNameB); | |
}); | |
} | |
let sorted = sortArray([ | |
{ name: "Harry Potter", rating: "8+", author: "Joanne Rowling" }, | |
{ name: "Warcross", rating: "13+", author: "Marie Lu" }, | |
{ name: "The Hunger Games", rating: "12+", author: "Suzanne Collins" }, | |
]); | |
console.log(sorted); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment