Created
April 30, 2021 03:03
-
-
Save fadhil-riyanto/57c46ec75d101d92e80d3591a2b5a450 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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