Skip to content

Instantly share code, notes, and snippets.

@deschantkn
Created March 9, 2020 09:01
Show Gist options
  • Save deschantkn/5eb5f561447db84476564870efcd6646 to your computer and use it in GitHub Desktop.
Save deschantkn/5eb5f561447db84476564870efcd6646 to your computer and use it in GitHub Desktop.
function countApplesAndOranges(s, t, a, b, apples, oranges) {
let noOfApples = 0;
let noOfOranges = 0;
const applePositions = apples.map(apple => apple + a);
const orangePositions = oranges.map(orange => orange + b);
console.log(applePositions, orangePositions);
for (let i = 0; i < applePositions.length; i++) {
if (applePositions[i] >= s && applePositions[i] <= t) {
applePositions[i];
noOfApples += 1;
}
}
for (let i = 0; i < orangePositions.length; i++) {
if (orangePositions[i] >= s && orangePositions[i] <= t) {
noOfOranges += 1;
}
}
console.log(noOfApples);
console.log(noOfOranges);
}
countApplesAndOranges(7, 11, 5, 15, [-2, 2, 1], [5, -6]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment