Created
September 8, 2015 22:38
-
-
Save jluismm2311/2d37d210ce6e3fcc4774 to your computer and use it in GitHub Desktop.
Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Polycarpus inserts a certain number of words "WUB…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function songDecoder(song){ | |
return song.replace(/(WUB)+/g, " ").trim(); | |
} |
can you explain this answer please
1.- Create an array separating the string using the word 'WUB' like separator ,
2.- Iterate over the new array and filter the elements that are not empty
3.- join the new array with an space
1.- var res = song.split('WUB')
2.- res = res.filter( s => {
if( s.legth !== 0 )
return s
} )
3.- res = res.join(' ')
return song.replace(/(WUB)+/g, " ").trim();
//this works
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
let songDecoder = song => song.split("WUB").filter(s => s.length !== 0).join(" ");