Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function secretChat(input) {
- input = input.slice(0, input.indexOf("Reveal"))
- let message = input.shift()
- const chat = {
- InsertSpace: insertSpace,
- Reverse: reverse,
- ChangeAll: changeAll,
- }
- function insertSpace(i) { message = `${message.substring(0, i)} ${message.substring(i)}` }
- function reverse(a) {
- if (!message.includes(a)) {
- console.log("error")
- return null
- }
- message = message.replace(a, "")
- message = `${message}${a.split("").reverse().join("")}`
- }
- function changeAll(a, b) {
- b = b.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&")
- const r = new RegExp(a, "g")
- message = message.replace(r, b)
- }
- input.forEach(x => {
- const [command, k, m] = x.split(":|:")
- if (chat[command](k, m) !== null) console.log(message)
- })
- console.log(`You have a new text message: ${message}`)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement