Skip to content

Instantly share code, notes, and snippets.

@deepaknverma
Created April 27, 2017 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepaknverma/cc65ec9a0228dd08422ef0e802d03620 to your computer and use it in GitHub Desktop.
Save deepaknverma/cc65ec9a0228dd08422ef0e802d03620 to your computer and use it in GitHub Desktop.
count fruitedrop
/*
Sample Input 0
7 11
5 15
3 2
-2 2 1
5 -6
Explanation:
The first line contains two space-separated integers denoting the respective values of s and t.
The second line contains two space-separated integers denoting the respective values of a and b.
The third line contains two space-separated integers denoting the respective values of m and n.
The fourth line contains space-separated integers denoting the respective distances that each apple falls from point a.
The fifth line contains space-separated integers denoting the respective distances that each orange falls from point b.
*/
function calculateDrop() {
var s_temp = '7 11'.split(' ');
var s = parseInt(s_temp[0]);
var t = parseInt(s_temp[1]);
var a_temp = '5 15'.split(' ');
var a = parseInt(a_temp[0]);
var b = parseInt(a_temp[1]);
var m_temp = '3 2'.split(' ');
var m = parseInt(m_temp[0]);
var n = parseInt(m_temp[1]);
apple = '-2 2 1'.split(' ');
apple = apple.map(Number);
orange = '5 -6'.split(' ');
orange = orange.map(Number);
console.log(apple.map((item) => a + item).reduce((n, val) => { return (val >= s && val <= t) ? n + 1 : n + 0; }, 0));
console.log(orange.map((item) => b + item).reduce((n, val) => { return (val >= s && val <= t) ? n + 1 : n + 0;}, 0));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment