This one you can solve with a single RegExp:
const removeConsecutiveDuplicates = (input) => input.replace(/(\w+) \1/g, "$1") // \1 matches the last match made with (\w+)
Yeah, but backreferences are evil. ;)
Still pretty effective, especially in this case. ;)
I don't know too much about regex, I think I need to do some research about it 😅 what does the "$1" do?
It inserts the first match inside brackets.
Oh right, so it just leaves the first match and the other one gets replaced, am I rigth?
Exactly.
cool 🔥
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This one you can solve with a single RegExp:
Yeah, but backreferences are evil. ;)
Still pretty effective, especially in this case. ;)
I don't know too much about regex, I think I need to do some research about it 😅
what does the "$1" do?
It inserts the first match inside brackets.
Oh right, so it just leaves the first match and the other one gets replaced, am I rigth?
Exactly.
cool 🔥