• + 0 comments

    typescript boilerplate: 'use strict';

    process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString: string = ''; let inputLines: string[] = []; let currentLine: number = 0; process.stdin.on('data', function(inputStdin: string): void { inputString += inputStdin; });

    process.stdin.on('end', function(): void { inputLines = inputString.split('\n'); inputString = ''; main(); });

    function readLine(): string { return inputLines[currentLine++]; }

    class TextEditor { private currentText:string; // Enter your code here constructor(){ this.currentText ="" } append(w:string){ // Enter your code here } delete(k:number){ // Enter your code here } print(k:number){ // Enter your code here } undo(){ // Enter your code here } }

    type EditorMethod = "append" | "delete" | "print" | "undo";

    function main() { const commandMap = {"1": "append", "2": "delete", "3" : "print", "4": "undo" } as const;

    const textEditor = new TextEditor();
    inputLines.shift()
    inputLines.map((inputLine:string) => {
        const [command, input] = inputLine.split(" ") as ["1"|"2"|"3"|"4", string]
        const method = commandMap[command] 
        if (method == "undo") return textEditor.undo()
        if (method == "append") return textEditor.append(input);
    
        return textEditor[method](Number(input))
    } );
    

    }