From ae0efe07567dbc2a462a6bfa117dde4e78359ad1 Mon Sep 17 00:00:00 2001 From: Klagarge Date: Mon, 7 Apr 2025 13:05:27 +0200 Subject: [PATCH] feat: add genre filtering and longest streak display in TopSongs --- src/main/scala/TopSongs/TopSongs.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/scala/TopSongs/TopSongs.scala b/src/main/scala/TopSongs/TopSongs.scala index 29e1fb8..a34d455 100644 --- a/src/main/scala/TopSongs/TopSongs.scala +++ b/src/main/scala/TopSongs/TopSongs.scala @@ -122,6 +122,14 @@ case class TopSongs(songs: List[Song] = List()) { .toMap } + // This function return the song spent the most weeks on the chart + // It uses reduce to find the song with the maximum streak value + def longestStreak(): Song = { + songs.reduce((s1, s2) => { + if (s1.rank._1.streak.getOrElse(0) > s2.rank._1.streak.getOrElse(0)) s1 else s2 + }) + } + // This function returns the top N songs by weeks on chart // It sorts the songs by the streak value in descending order and takes the top N songs def topNSongsByWeeks(n: Int): List[Song] = {