Advertisement
Guest User

q1 sample answer

a guest
Mar 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function oneHitWonder(songList) {
  2.   const oneHits = [];
  3.  
  4.   const counter = songList.reduce((artistSongCounter, song) => {
  5.     if (artistSongCounter[song.artist]) {
  6.       artistSongCounter[song.artist].count++;
  7.     } else {
  8.       artistSongCounter[song.artist] = { count: 1 };
  9.     }
  10.     return artistSongCounter;
  11.   }, {});
  12.  
  13.   for (let artist in counter) {
  14.     if (counter[artist].count < 2) {
  15.       oneHits.push(artist);
  16.     }
  17.   }
  18.   return oneHits;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement