Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 805c1cd

Browse files
committed
Add a question
1 parent f335eb2 commit 805c1cd

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

‎README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,3 +1247,44 @@ const maxProfit = prices => {
12471247
---
12481248

12491249
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**
1250+
1251+
## 39. Dubstep
1252+
1253+
Mike works as a DJ in the best London 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 (that don't contain `WUB`). To make the dubstep remix of this song, Mike inserts a certain number of words `WUB` before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including `WUB`, in one string and plays the song at the club.
1254+
1255+
For example, a song with words "I AM X" can transform into a dubstep remix as `WUBWUBIWUBAMWUBWUBX` and cannot transform into `WUBWUBIAMWUBX`.
1256+
1257+
Recently, Johnny has heard Mike's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Mike remixed. Help Johnny restore the original song.
1258+
1259+
*Input*: The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters
1260+
1261+
*Output*: Return the words of the initial song that Mike used to make a dubsteb remix. Separate the words with a space.
1262+
1263+
```js
1264+
const songDecoder = song => {
1265+
// Your solution
1266+
}
1267+
1268+
console.log(songDecoder("AWUBBWUBC"));
1269+
// 'A B C' (WUB should be replaced by 1 space)
1270+
console.log(songDecoder("AWUBWUBWUBBWUBWUBWUBC"));
1271+
// 'A B C' (Multiples WUBs should be replaced by only 1 space)
1272+
console.log(songDecoder("WUBAWUBBWUBCWUB"));
1273+
// 'A B C' (Any starting or trailing WUBs should be removed)
1274+
console.log(songDecoder("WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB"));
1275+
// 'WE ARE THE CHAMPIONS MY FRIEND'
1276+
```
1277+
1278+
<details><summary>Solution</summary>
1279+
1280+
```js
1281+
const songDecoder = song => {
1282+
return song.replace(/(WUB)+/g, ' ').trim();
1283+
}
1284+
```
1285+
1286+
</details>
1287+
1288+
---
1289+
1290+
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /