test-no-short-tracks.js 661 B

1234567891011121314151617181920212223242526
  1. export default function({
  2. albumData,
  3. getTotalDuration,
  4. }) {
  5. const shortAlbums = albumData
  6. .filter(album => album.tracks.length > 1)
  7. .map(album => ({
  8. album,
  9. duration: getTotalDuration(album.tracks),
  10. }))
  11. .filter(album => album.duration)
  12. .filter(album => album.duration < 60 * 15);
  13. if (!shortAlbums.length) return true;
  14. shortAlbums.sort((a, b) => a.duration - b.duration);
  15. console.log(`Found ${shortAlbums.length} short albums! Oh nooooooo!`);
  16. console.log(`Here are the shortest 10:`);
  17. for (const {duration, album} of shortAlbums.slice(0, 10)) {
  18. console.log(`- (${duration}s)`, album);
  19. }
  20. return false;
  21. }