« get me outta code hell

test-no-short-tracks.js « data-tests - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/data-tests/test-no-short-tracks.js
blob: 7635609915b6436a67cd04766ea7a64878bf68d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
export default function({
  albumData,
  getTotalDuration,
}) {
  const shortAlbums = albumData
    .filter(album => album.tracks.length > 1)
    .map(album => ({
      album,
      duration: getTotalDuration(album.tracks),
    }))
    .filter(album => album.duration)
    .filter(album => album.duration < 60 * 15);

  if (!shortAlbums.length) return true;

  shortAlbums.sort((a, b) => a.duration - b.duration);

  console.log(`Found ${shortAlbums.length} short albums! Oh nooooooo!`);
  console.log(`Here are the shortest 10:`);
  for (const {duration, album} of shortAlbums.slice(0, 10)) {
    console.log(`- (${duration}s)`, album);
  }

  return false;
}