Answer the question
In order to leave comments, you need to log in
How to determine the leadership in the match?
Hello.
We have two arrays - the minutes when teams A and B scored, respectively. The match lasts (conditionally) 90 minutes. How can you determine in what time intervals team A and team B were in the lead, so that you can then calculate how many minutes team A was in the lead, and how many team B was in the lead. An example of arrays is [12, 34, 56] and And she scored the ball at 12 minutes, then at 34, then at 56). Team B scored the ball in 45 minutes. There may be a story that the number of heads is equal and so on.
How to determine how many minutes match A and match B won? Preferably in Python or JS
Answer the question
In order to leave comments, you need to log in
const totalTime = 90;
const a = [12, 34, 56];
const b = [45];
let score = 0;
let aWin = 0;
let bWin = 0;
let draw = 0;
for (let i=0;i<totalTime;i++){
score+=(a.indexOf(i)!=-1?1:0)-(b.indexOf(i)!=-1?1:0);
aWin += score>0?1:0;
bWin += score<0?1:0;
draw += score==0?1:0;
};
console.log("a - " + aWin + " minutes");
console.log("b - " + bWin + " minutes");
console.log("a=b - " + draw + " minutes");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question