Skip to content

Instantly share code, notes, and snippets.

@jluismm2311
Created September 8, 2015 22:38
Show Gist options
  • Save jluismm2311/2d37d210ce6e3fcc4774 to your computer and use it in GitHub Desktop.
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…
function songDecoder(song){
return song.replace(/(WUB)+/g, " ").trim();
}
@jay51
Copy link

jay51 commented Nov 4, 2018

let songDecoder = song => song.split("WUB").filter(s => s.length !== 0).join(" ");

@IamGiel
Copy link

IamGiel commented Feb 21, 2019

can you explain this answer please

@negope
Copy link

negope commented Jun 23, 2019

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(' ')

@Nyambura254
Copy link

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