Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
You missed the "non-negative integers" requirement.
Good thing about this solution: Super super beginner friendly answer using an essential loop statement
Damn
good job
argh, I forgot about the + on regExp, I just used a filter to remove the extra spaces xd
"Yay, finally i found a single line regex magicfuckery solution like others too!!". compares with other solutions Oh... Well, anyways.
Mine was so complicated simply because i replaced every single WUB with 1 space, ending up with so 3-4 spaces on recurring WUBs. So I had to handle that.
All i needed was a single "+" on my regex, that's pretty smart. Slowly learning regex, it's fascinating.
(+) operator doing that job
eg:"WUBWUBWUBWUB".replace(/(WUB)/g) is equal to " " so in this case we get four empty spaces. because it replace every WUB into empty string tha't why we are using + symbol it means it check minimum one 'WUB' matches.
eg1:"WUB".replace(/(WUB)+/g) is equal to " ",
eg2:"WUBWUB".replace(/(WUB)+/g) is equal to " ",
eg3:"WUBWUBWUBWUB".replace(/(WUB)+/g) is equal to " ".in this case there are fout 'WUB' substrings are here so it replace that string into one empty string
How does this code remove the multiple spaces? I can only understand how it replaces the WUBs with a space each time, not how it accounts for the potential multiple spaces
^ CORRECTIONS AND TO BE MORE SPECIFIC:
The + means to match whatever is infront of it 1 or more times**
Then you have the astric * (which is not included but important to differentiate from the plus) it matches whatever is infront of it from 0 or more times.
And finally g the global tells regex to not stop after the first match but continue and look for more matches
This was a great exercise to start to really dip my toes into regex and play around with some stuff. I am glad I got the same result here!
man thats very clever, gg
This comment is hidden because it contains spoiler information about the solution
I'm curious on all these .repalce() answers does the .trim() have to loop over the string a second time? I wonder if there is a way to get it in one pass?
Nice, very short code.
But, it works!
i dont even know why i cant think like this lol
Loading more items...