Camel Case 4

  • + 0 comments

    I dont know what is wrong with this code. its give correct output still test cases are getting failed. can somebody help me with that. code in JSI don't know what is wrong with this code. It's giving the correct output, yet the test cases are failing. Can somebody help me with that? The code is in JS.

    function processData(input) { input = input.split('\n');

    // Helper function to combine words into camelCase
    function combineWords(type, name) {
        let words = name.split(' ');
    
        // Capitalize the first letter of each word (except for the first one in the case of methods/variables)
        let camelCaseName = words[0].toLowerCase() + words.slice(1)
            .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
            .join('');
    
        // Handle method, variable, and class naming rules
        if (type === 'M') {
            return camelCaseName + '()';  // Method name ends with parentheses
        } else if (type === 'V') {
            return camelCaseName;  // Variable name is just camelCase
        } else if (type === 'C') {
            return camelCaseName.charAt(0).toUpperCase() + camelCaseName.slice(1);  // Class name starts with uppercase
        }
    }
    
    // Helper function to split camelCase name into space-delimited words
    function splitCamelCase(name) {
        return name.split(/(?=[A-Z])/).join(' ').toLowerCase().replace('()', '');
    }
    
    // Process each line of input
    input.forEach(line => {
        let [operation, type, name] = line.split(';');
    
        // Perform split operation
        if (operation === 'S') {
            const splitName = splitCamelCase(name);
            console.log(splitName);
        }
        // Perform combine operation
        else if (operation === 'C') {
            const combinedName = combineWords(type, name);
            console.log(combinedName);
        }
    });
    

    }