• + 0 comments

    Javascript solution:-

    function countApplesAndOranges(s, t, a, b, apples, oranges) {
        const isFallingOnHouse = (startPoint) => ((prev, frute) => {
            const position = startPoint + frute;
            if (position >= s & position <= t) prev++;
            return prev;
        })
        const appleFallsOnHouse = apples.reduce(isFallingOnHouse(a), 0)
        console.log(appleFallsOnHouse);
        const orangesFallsOnHouse = oranges.reduce(isFallingOnHouse(b), 0)
        console.log(orangesFallsOnHouse);
    }