Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let chat = input.shift()
- let token = input.shift()
- while(token !== `Reveal`) {
- let [comand,checkOne,checkTwo] = token.split(`:|:`)
- if(comand === `InsertSpace`) {
- chat = space(chat,checkOne)
- } else if(comand === `Reverse`) {
- chat = reversee(chat,checkOne)
- } else if(comand === `ChangeAll`) {
- chat = change(chat,checkOne,checkTwo)
- }
- token = input.shift()
- }
- console.log(`You have a new text message: ${chat}`)
- function space(array,index) {
- let result = ``
- let firstPart = ``
- firstPart = array.slice(0,index)
- let secondPart = ``
- secondPart = array.slice(index)
- result = result.concat(firstPart,` `,secondPart)
- array = result
- console.log(array)
- return array
- }
- function reversee(array,substring) {
- let result = ``
- let finalRes = ``
- let ind = array.indexOf(substring)
- if(ind > 0) {
- let checkInd = array.slice(ind)
- let revCheck = checkInd.split(``).reverse().join(``)
- result = array.substring(0,ind)
- let finalRes = ``
- finalRes = finalRes.concat(result,revCheck)
- array = finalRes
- console.log(array)
- }
- else {
- console.log(`error`)
- }
- return array
- }
- function change(array,substring,replacement) {
- let result = ``
- for(let i=0;i<array.length;i++) {
- if(array[i] == substring) {
- result += replacement
- } else {
- result += array[i]
- }
- }
- console.log(result)
- return result
- }
- }
Add Comment
Please, Sign In to add comment