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
2 Respostas
+ 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)
+ 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.