Skip to content

Commit

Permalink
Question CastonPursuit#13 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronConstant committed Jan 18, 2024
1 parent ea9a621 commit c14294a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,12 @@ function printLongestSongTitle(songs) {
* @param {Object[]} songs - An array of songs.
* @returns {Object[]} Sorted array of songs.
*/
function sortSongsByArtistAndTitle(songs) {}
function sortSongsByArtistAndTitle(songs) {
songs.sort((a, b) => { const artistListing = a.artist.localeCompare(b.artist);

return artistListing === 0 ? a.title.localeCompare(b.title) : artistListing;
});
}

// Problem #14
/**
Expand Down
19 changes: 7 additions & 12 deletions testCode
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,14 @@ const exampleSongData = require("./data/songs");

// console.log(getSongsWithDurationInMinutes(exampleSongData))

function printLongestSongTitle(songs) {
let songTitleList = songs.map(song => {
return song.title;
});

const longestTitle = songTitleList.reduce((longestSong, currentSong) => {
return currentSong.length > longestSong.length ? currentSong : longestSong;
});

console.log(longestTitle);
}
function sortSongsByArtistAndTitle(songs) {
let songArtists =songs.sort((a,b) => { return a.artist.localeCompare(b.artist)
})
let organizeByTitle = songArtists.sort((a,b) => { return a.title.localeCompare(b.title) } )
return organizeByTitle;
}



console.log(printLongestSongTitle(exampleSongData))
console.log(sortSongsByArtistAndTitle(exampleSongData))

0 comments on commit c14294a

Please sign in to comment.