You are viewing a single comment's thread. Return to all comments →
function countApplesAndOranges(start: number, end: number, appleTree: number, orangeTree: number, apples: number[], oranges: number[]): void { let applesCount = 0, orangesCount = 0; for (let index = 0; index < Math.max(apples.length, oranges.length); index ++) { const applePosition = appleTree + apples?.[index]; const orangePosition = orangeTree + oranges?.[index]; if (!Number.isNaN(applePosition) && applePosition >= start && applePosition <= end) { applesCount++; } if (!Number.isNaN(orangePosition) && orangePosition >= start && orangePosition <= end) { orangesCount++; } } console.log(applesCount.toString()); console.log(orangesCount.toString()); }
Seems like cookies are disabled on this browser, please enable them to open this website
Apple and Orange
You are viewing a single comment's thread. Return to all comments →