Advertisement
bebo231312312321

Untitled

Mar 23rd, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function secretChat(input) {
  3.     input = input.slice(0, input.indexOf("Reveal"))
  4.     let message = input.shift()
  5.     const chat = {
  6.         InsertSpace: insertSpace,
  7.         Reverse: reverse,
  8.         ChangeAll: changeAll,
  9.     }
  10.     function insertSpace(i) { message = `${message.substring(0, i)} ${message.substring(i)}` }
  11.     function reverse(a) {
  12.         if (!message.includes(a)) {
  13.             console.log("error")
  14.             return null
  15.         }
  16.         message = message.replace(a, "")
  17.         message = `${message}${a.split("").reverse().join("")}`
  18.     }
  19.     function changeAll(a, b) {
  20.         b = b.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&")
  21.         const r = new RegExp(a, "g")
  22.         message = message.replace(r, b)
  23.     }
  24.     input.forEach(x => {
  25.         const [command, k, m] = x.split(":|:")
  26.         if (chat[command](k, m) !== null) console.log(message)
  27.     })
  28.     console.log(`You have a new text message: ${message}`)
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement