Camel Case 4

  • + 0 comments

    It is show the answer ,as it expected but still smae issue "wrong answer"

    function processInput(input) {
        const [operation, type, words] = input.split(";");
    
        if (operation === "S") {
            // SPLIT operation: Insert spaces before uppercase letters, remove "()" for methods
            let result = words.replace(/\(\)$/, '')  // Remove () for methods
                              .replace(/([A-Z])/g, ' $1')  // Insert space before uppercase
                              .toLowerCase()
                              .trim();
            console.log(result);
        } 
        
        else if (operation === "C") {
            // COMBINE operation: Convert to CamelCase
            let wordsArray = words.split(" ");
            let result = wordsArray.map((word, index) =>
                index === 0 && type !== "C" ? word.toLowerCase()  // First word lowercase (except Class)
                : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()  // Capitalize others
            ).join('');
    
            if (type === "M") result += "()"; // Append () for methods
            console.log(result);
        }
    }
    

    Wrong Answer Input (stdin) S;V;iPad C;M;mouse pad C;C;code swarm S;C;OrangeHighlighter Your Output (stdout) i pad mousePad () CodeSwarm orange highlighter Expected Output i pad mousePad() CodeSwarm orange highlighter