Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- secretChat1 = inputArray => {
- 'use strict'
- let workArray = inputArray.slice()
- let concealedMessage = workArray.shift()
- let commands = workArray.shift()
- while (commands !== 'Reveal') {
- let command = commands.split(':|:')
- if (command[0] === 'InsertSpace') {
- concealedMessage = concealedMessage.substring(0, +command[1]) + ' ' +
- concealedMessage.substring(+command[1], concealedMessage.length)
- console.log(concealedMessage)
- } else if (command[0] === 'Reverse') {
- if (concealedMessage.includes(command[1])) {
- concealedMessage = concealedMessage.replace(command[1], '')
- let reverseTmp = command[1]
- .split('')
- .reverse()
- .join('')
- concealedMessage = concealedMessage.concat(reverseTmp)
- console.log(concealedMessage)
- }
- else
- console.log('error')
- } else if (command[0] === 'ChangeAll') {
- while (concealedMessage.includes(command[1]))
- concealedMessage = concealedMessage.replace(command[1], command[2])
- console.log(concealedMessage)
- }
- commands = workArray.shift()
- }
- console.log(`You have a new text message: ${concealedMessage}`)
- }
- secretChat1([
- 'heVVodar!gniV',
- 'ChangeAll:|:V:|:l',
- 'Reverse:|:!gnil',
- 'InsertSpace:|:5',
- 'Reveal'
- ])
Add Comment
Please, Sign In to add comment