Java script code plz

Asked by Ashish Yadav about 5 months ago

0

In XYZ country there is rule that car's engine no. depends upon car' number plate. Engine no is sum of all the integers present on car's Number plate. The issuing authority has hired you in order to provide engine no. to the cars. Your task is to develop an algorithm which takes input as in form of string (Number plate) and gives back Engine number. Input You are given a string 's Output Print the number plate Example Input HR05-AA-2669 Output 28 Select your language 1 const readline 2 const inp = read input: process 4 }); 5 const userInput 6 inp.on("line" 7 userInput. push ( 8

1 Answer

    0
    function getEngineNumber(str) {
        let numberPlate = str.split('');
        let engineNum = 0; 
        for(let digit of numberPlate) {
            if(Number.isInteger(parseInt(digit))) {
                engineNum += parseInt(digit);
            }
        }
    
        return engineNum;
    }
    
    console.log(getEngineNumber('HR05-AA-2669')); // 28
    console.log(getEngineNumber('HR09-AA-1119')); // 21
    console.log(getEngineNumber('HR00-AA-1337')); // 14
    
    
    @pranavtechie

    Pranav Mandava

    @pranavtechie

    Your answer