DEV Community

Discussion on: #25 - Remove consecutive duplicate words CodeWars Kata (7 kyu)

Collapse
 
loucyx profile image
Lou Cyx

Try this, is faster:

const removeConsecutiveDuplicates = string =>
    string
        .split(" ")
        .filter(
            (word, index, splittedString) => word !== splittedString[index + 1],
        )
        .join(" ");
Enter fullscreen mode Exit fullscreen mode

Cheers!

Collapse
 
cesar__dlr profile image
Cesar Del rio

Great Solution, I didn't know that you could call the filtered array as a parameter! 🙌