0

Can we simplify words that contains some same letters?

in example, someone inputted "meeeeee" then it's simplified to be "me" it's not limiting the input to be 2 letters

9th Oct 2020, 11:18 AM
Wan
Wan - avatar
2 Respuestas
+ 6
var b=new Set("meeee") Set object removes duplicates Edit:you can get the string back using var a=""; b.forEach((val)=>{ a+=val }) console.log(a)
9th Oct 2020, 11:22 AM
Abhay
Abhay - avatar
+ 6
Another possible solution using regex: var text = "is thiiiis better?"; text = text.replace(/(\w)(?=\1)/g, ""); console.log(text) // "is this beter?" Note that it will reduce all double letters, not just ones that don't make sense.
9th Oct 2020, 11:30 AM
Russ
Russ - avatar