JSFiddle - React, Tailwind, and code Playground

Fruit falling from Tree, check if it falls in house.

by Nalin Sajwan

JavaScript

/*7, 11
5, 15
3, 2
-2, 2, 1
5, -6*/

function getDistance(fD, t) {
    return fD + t;
}

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

	let apple = 0;
    let orange = 0;
  
    for (let i = 0; i < apples.length; i++) {
        let dist = getDistance(apples[i], a);
        if (dist >= s && dist <= t) {
        	apple++;
        }
    }

    for (let i = 0; i < oranges.length; i++) {
        let dist = getDistance(oranges[i], b);
        if (dist >= s && dist <= t) {
        	orange++;
        }
    }

    console.log(apple, orange)
}

calculateCounts(7, 11, 5, 15, [-2, 2, 1], [5, -6])