Hi good people! I’m trying to solve a JavaScript challenge, but my code is not working as expected
/*
PROBLEM: Write a function called getMainArtists which takes in an array of songs
and returns an array of the primary artists on the recordings.
If there's only one artist, that artist should be returned;
if there are featured artists, they should be ignored
(so only the artist to the left of "featuring" is kept.)
*/
//My Code Solution...
function getMainArtists(arr){
return arr.map(function(val){
if ((val.artist).includes("featuring")){
return null;
} else {
return val.artist;
}
})
}
getMainArtists(songs);
/*
The data I'm using can be found here https://github.com/PJMantoss/iterators2/blob/master/data.js
*/
PROBLEM STATEMENT: When I run getMainArtists(songs) it returns an array of artist names excluding names that contain ‘featuring’. It’s suppose to also return artist names that have ‘featuring’, but should only leave out all the words starting from ‘featuring’. Any ideas how I can refactor my code to work? Thank you for your help