aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers/searchSong.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers/searchSong.ts')
-rw-r--r--src/helpers/searchSong.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/helpers/searchSong.ts b/src/helpers/searchSong.ts
new file mode 100644
index 0000000..24132f6
--- /dev/null
+++ b/src/helpers/searchSong.ts
@@ -0,0 +1,20 @@
+import { songs } from "../constants";
+import { Song } from "../types/song";
+
+export function searchSong(searchTerm: string): Song[] {
+ searchTerm = searchTerm.toLowerCase();
+
+ return songs
+ .filter((song: Song) => {
+ const songName = song.name.toLowerCase();
+ const songArtist = song.artist.toLowerCase();
+
+ if (songArtist.includes(searchTerm) || songName.includes(searchTerm)) {
+ return song;
+ }
+ })
+ .sort((a, b) =>
+ a.artist.toLowerCase().localeCompare(b.artist.toLocaleLowerCase())
+ )
+ .slice(0, 5);
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage