Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function oneHitWonder(songList) {
- const oneHits = [];
- const counter = songList.reduce((artistSongCounter, song) => {
- if (artistSongCounter[song.artist]) {
- artistSongCounter[song.artist].count++;
- } else {
- artistSongCounter[song.artist] = { count: 1 };
- }
- return artistSongCounter;
- }, {});
- for (let artist in counter) {
- if (counter[artist].count < 2) {
- oneHits.push(artist);
- }
- }
- return oneHits;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement