• + 0 comments

    /Solved in JavaScript (Node.js)/

    function countApplesAndOranges(s, t, a, b, apples, oranges) {

    let landedA = []; // Insertion the final position of all Apples
    let landedB = [];// Insertion the final position of all Oranges
    
    for(let i = 0; i < apples.length; i++){
        landedA.push(apples[i] + a); // thrown distance + Apple tree position
    }
    
    for(let i = 0; i < oranges.length; i++){
        landedB.push(oranges[i] + b); // thrown distance + Orange tree position
    }
    
    let countApples = 0;
    let countOranges = 0;
    
        /* counter for both fruits. If they are between the constraints,
        the value is increased by one*/
    
    for(let i = 0; i < landedA.length; i++){
        if(landedA[i] >= s && landedA[i] <= t){
            countApples++;
        }
    }
    
    for(let i = 0; i < landedB.length; i++){
        if(landedB[i] >= s && landedB[i] <= t){
            countOranges++;
        }
    
             console.log(countApples);
            console.log(countOranges);
    
    }
    
    
    
    console.log(countApples);
    console.log(countOranges);
    

    }