blob: 01f6304e8a82f490c18db48554bf68c6179e178c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
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())
);
}
|