-
Notifications
You must be signed in to change notification settings - Fork 0
Make brute force song-sorting more efficient #1
Copy link
Copy link
Open
Description
The function that matches the song bank to their respective seasonal playlists uses a brute-force nested for-loop method. This could be more efficient by shifting off a playlist once the first that isn't sorted into it is detected. This would work because the songs are chronologically sorted - so once a song can't be matched to a playlist then none of the others will either.
createPlaylists() {
const playlistArray = this.createResponseObject(this.state.songs[0].added_at,
this.state.songs[this.state.songs.length - 1].added_at);
const songs = this.state.songs;
songs.forEach(song => {
const songDate = new Date(song.added_at);
const [songYear, songMonth] = [songDate.getFullYear(), songDate.getUTCMonth()];
playlistArray.forEach(playlist => {
if (songYear === playlist.year && playlist.months.includes(songMonth)) {
playlist.songs.push(song);
}
});
});
this.setState({playlists: playlistArray});
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels