Skip to content

Instantly share code, notes, and snippets.

@fadhil-riyanto
Created April 30, 2021 03:03
Show Gist options
  • Save fadhil-riyanto/57c46ec75d101d92e80d3591a2b5a450 to your computer and use it in GitHub Desktop.
Save fadhil-riyanto/57c46ec75d101d92e80d3591a2b5a450 to your computer and use it in GitHub Desktop.
function rampingkan_teks(string, type) {
if (type == "NEW_LINE") {
ipes = '\r\n';
} else if (type == "SPACE") {
ipes = " ";
} else if (type == "KOMA") {
ipes = ",";
} else if (type == "TITIK") {
ipes = ".";
} else if (type == "NEW_LINE_SPACE") { ipes = '\r\n' + " "; }
inp = string;
exp = inp.split(ipes);
index = 0;
res = [];
exp.forEach((expp) => {
if (expp == exp[index + 1]) {
expp = null;
}
res.push(expp);
index = index + 1;
});
masak = res.join(" ")
regex = masak.replace(/\s+/g, ' ');
return regex.trim();
}
console.log(rampingkan_teks("Kucing Kucing mumu bulat meong meong nyan cat makan makan makan sosis", "SPACE"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment