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