#25 - Remove consecutive duplicate words CodeWars Kata (7 kyu) Cesar Del rio on January 25, 2022 Instructions Your task is to remove all consecutive duplicate words from a string, leaving only first words entries. For example: In... Read full post Collapse Expand Alex Lohr Alex Lohr Alex Lohr Follow ...former musician, voice actor, martial artist, started coding 38 years ago and turned front-end developer 25+ years ago. Email alex.th.kloss.77@googlemail.com Location Germany Work Senior Frontend Developer at CrabNebula Joined Jun 13, 2017 • Jan 25 '22 Dropdown menu Copy link Hide 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+) Enter fullscreen mode Exit fullscreen mode Collapse Expand FJones FJones FJones Follow Location Munich, Germany Work Software Development Team Lead Joined Oct 4, 2019 • Jan 25 '22 Dropdown menu Copy link Hide Yeah, but backreferences are evil. ;) Collapse Expand Alex Lohr Alex Lohr Alex Lohr Follow ...former musician, voice actor, martial artist, started coding 38 years ago and turned front-end developer 25+ years ago. Email alex.th.kloss.77@googlemail.com Location Germany Work Senior Frontend Developer at CrabNebula Joined Jun 13, 2017 • Jan 25 '22 Dropdown menu Copy link Hide Still pretty effective, especially in this case. ;) Collapse Expand Cesar Del rio Cesar Del rio Cesar Del rio Follow Join me on my road to mastering coding. 100 days of codewars challenge. Email cesardelriodlr@outlook.com Location México Work CEO at Mercurio Agencia Digital Joined Dec 29, 2021 • Jan 25 '22 Dropdown menu Copy link Hide I don't know too much about regex, I think I need to do some research about it 😅 what does the "$1" do? Collapse Expand Alex Lohr Alex Lohr Alex Lohr Follow ...former musician, voice actor, martial artist, started coding 38 years ago and turned front-end developer 25+ years ago. Email alex.th.kloss.77@googlemail.com Location Germany Work Senior Frontend Developer at CrabNebula Joined Jun 13, 2017 • Jan 25 '22 Dropdown menu Copy link Hide It inserts the first match inside brackets. Cesar Del rio Cesar Del rio Cesar Del rio Follow Join me on my road to mastering coding. 100 days of codewars challenge. Email cesardelriodlr@outlook.com Location México Work CEO at Mercurio Agencia Digital Joined Dec 29, 2021 • Jan 25 '22 Dropdown menu Copy link Hide Oh right, so it just leaves the first match and the other one gets replaced, am I rigth? Alex Lohr Alex Lohr Alex Lohr Follow ...former musician, voice actor, martial artist, started coding 38 years ago and turned front-end developer 25+ years ago. Email alex.th.kloss.77@googlemail.com Location Germany Work Senior Frontend Developer at CrabNebula Joined Jun 13, 2017 • Jan 25 '22 Dropdown menu Copy link Hide Exactly. Cesar Del rio Cesar Del rio Cesar Del rio Follow Join me on my road to mastering coding. 100 days of codewars challenge. Email cesardelriodlr@outlook.com Location México Work CEO at Mercurio Agencia Digital Joined Dec 29, 2021 • Jan 25 '22 Dropdown menu Copy link Hide cool 🔥 Collapse Expand Cesar Del rio Cesar Del rio Cesar Del rio Follow Join me on my road to mastering coding. 100 days of codewars challenge. Email cesardelriodlr@outlook.com Location México Work CEO at Mercurio Agencia Digital Joined Dec 29, 2021 • Jan 25 '22 Dropdown menu Copy link Hide Great Solution, I didn't know that you could call the filtered array as a parameter! 🙌 Collapse Expand Matetlot Matetlot Matetlot Follow Joined Sep 18, 2021 • Jan 25 '22 Dropdown menu Copy link Hide What a conversation of genius, well donne guys ! Collapse Expand Cesar Del rio Cesar Del rio Cesar Del rio Follow Join me on my road to mastering coding. 100 days of codewars challenge. Email cesardelriodlr@outlook.com Location México Work CEO at Mercurio Agencia Digital Joined Dec 29, 2021 • Jan 26 '22 Dropdown menu Copy link Hide Thanks bro 🙌 Code of Conduct • Report abuse For further actions, you may consider blocking this person and/or reporting abuse
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 🔥
Great Solution, I didn't know that you could call the filtered array as a parameter! 🙌
What a conversation of genius, well donne guys !
Thanks bro 🙌