Answer:
function removePartyKillers(playlist){
for(var i=0; i < playlist.length; i++){
if((playlist[i].durationInSeconds) > 480){
playlist.splice(i, 1);
}
}
console.log(playlist);
}
Step-by-step explanation:
When 8 minutes is converted to seconds, we have 480 seconds, that is 60 * 8 = 480. So, song whose duration is greater than 480 is removed.
The function has a for loop that loop through the entire playlist.
Inside the for loop, there is an if statement that check if for each song the durationInSeconds is greater than 480; once a durationInSeconds is greater than 480, that particular element is removed using the splice inbuilt method.
The splice method takes two arguments, the index at which to remove/add an element and the second element which is the number of elements to remove/add. The splice method returns a modified array.
Lastly, the modified array is logged to the console.