// search or browse filter
// given an album i want only the songs
// that are less than some max # of seconds
/**
Input: an Album instance and a max length per song
Output: an array of song ids that meet criteria
*/
var filterToMaxSongLength = function(album, maxSongLength) {
return album.songs.filter(function(songId) {
var song = getSongById(songId);
return song.duration < maxSongLength;
});
};
// render the filtered songs
for (var i = 0; i < filteredSongs.length; i++) {
var songId = filteredSongs[i];
var songData = getSongById(songId);
var element = document.createElement('H1');
element.innerText = songData.title;
document.body.appendChild(element);
}
h1 {
color: red;
}
This was a group exercise in making a tiny clone of functionality of some well-known app.
We chose Spotify.
Here are the data models of key nouns in the app.
```
var Song = {
id: '', // 1232387
artist: null, // points at an Artist
title: '', // Purple Heart Highway
year: null, // 2014
genre: null, // 'gospel', 'triphop', 'grunge'
duration: null, // 194 (seconds)
thumbnailURL: null, //
fileURL: null,
};
// Album
var Album = {
title: null,
releaseYear: null,
genre: null,
publisher: null,
thumbnail: null,
songs: [
1234,
1235,
1236,
1237,
],
};
```