Skip to content

Instantly share code, notes, and snippets.

@fachryansyah
Created December 23, 2019 09:19
Show Gist options
  • Save fachryansyah/c78c3ca1eb8407fbf6a968dcda748aa3 to your computer and use it in GitHub Desktop.
Save fachryansyah/c78c3ca1eb8407fbf6a968dcda748aa3 to your computer and use it in GitHub Desktop.
const command = (cmd, text, position) => {
let index = position - 1;
let countL = 0;
let countB = 0;
cmd.map(item => {
if(item === "l"){
countL += 1
console.log(`L : ${L(text, position + countL)}`)
}
if(item === "b"){
countB += 1
console.log(`B : ${B(text, position + countB)}`)
}
})
}
const L = (text, position) => {
const splitText = text.split("")
splitText[position] = `[${splitText[position]}]`
return splitText.join("")
}
const B = (text, position) => {
const splitTextBySpace = text.split(" ")
const splitText = splitTextBySpace[position].split("")
splitText[0] = `[${splitText[0]}]`
splitTextBySpace[position] = splitText.join("")
return splitTextBySpace.join(" ")
}
// console.log(l("helo"))
const dataA = "aku mau hidup seribu tahun lagi"
const dataB = "robohnya surau kami"
console.log("===[OUTPUT]===")
command(["l", "l"], dataA, 3)
command(["b"], dataB, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment