Simple Text Editor

  • + 1 comment

    Anyone have any idea why this is not working

    function processData(input) {
        //Enter your code here
        let numberOfOpps = parseInt(input[0]);
        let inputs = input.split("\n").slice(1); 
        let stack = []; 
        let currentString = ""; 
        for(let i = 0; i < numberOfOpps; i++){ 
             let opperation = inputs[i].split(" "); 
             let code = parseInt(opperation[0]); 
             let string = opperation[1];
             if(code == 1){ 
                stack.push(currentString); 
                currentString = currentString.concat(string); 
                // console.log("CURRENT STRING", currentString); 
             }else if (code == 2){ 
                stack.push(currentString); 
                let index = (currentString.length - parseInt(string) -1);
                if(index <= 0){ 
                    currentString = ""; 
                }else{
                    currentString = currentString.slice(0, index);
                }
                // console.log("CURRENT STRING", currentString);
             }else if (code == 3){ 
                let index = (parseInt(string) - 1);
                 console.log(currentString[index]);
             }else if(code == 4){ 
                currentString = stack.pop(); 
                // console.log("CURRENT STRING", currentString);
             }
        }
    }