dabidabidesh

secretChat1

Jul 18th, 2020
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. secretChat1 = inputArray => {
  2.   'use strict'
  3.  
  4.   let workArray = inputArray.slice()
  5.  
  6.   let concealedMessage = workArray.shift()
  7.  
  8.   let commands = workArray.shift()
  9.  
  10.   while (commands !== 'Reveal') {
  11.     let command = commands.split(':|:')
  12.  
  13.     if (command[0] === 'InsertSpace') {
  14.       concealedMessage = concealedMessage.substring(0, +command[1]) + ' ' +
  15.         concealedMessage.substring(+command[1], concealedMessage.length)
  16.       console.log(concealedMessage)
  17.     } else if (command[0] === 'Reverse') {
  18.       if (concealedMessage.includes(command[1])) {
  19.         concealedMessage = concealedMessage.replace(command[1], '')
  20.         let reverseTmp = command[1]
  21.           .split('')
  22.           .reverse()
  23.           .join('')
  24.         concealedMessage = concealedMessage.concat(reverseTmp)
  25.         console.log(concealedMessage)
  26.       }
  27.       else
  28.         console.log('error')
  29.     } else if (command[0] === 'ChangeAll') {
  30.       while (concealedMessage.includes(command[1]))
  31.         concealedMessage = concealedMessage.replace(command[1], command[2])
  32.       console.log(concealedMessage)
  33.     }
  34.  
  35.     commands = workArray.shift()
  36.   }
  37.  
  38.   console.log(`You have a new text message: ${concealedMessage}`)
  39. }
  40.  
  41. secretChat1([
  42.   'heVVodar!gniV',
  43.   'ChangeAll:|:V:|:l',
  44.   'Reverse:|:!gnil',
  45.   'InsertSpace:|:5',
  46.   'Reveal'
  47. ])
Add Comment
Please, Sign In to add comment