-1

the problem is an image so I'll try to abbreviate and write it out:

there are 2 football teams. For every match of team B compute the total number of matches that team A has scored less than or equal to team B in that match. For example:

team A : [2,3,4]
team B : [3,5]

the output will be : [2,3]

my solution so far:

function counts(teamA, teamB) {
    var arr = []
    for (var i = 0; i < teamB.length; i++){
        let newArr = teamA.filter(some => some <= teamB[i])
        arr.push(newArr.length)
            }
    return arr
}

Only some test cases pass (can't see what isn't passing). Any thoughts as to what I'm missing here?

edit: Here is another test case as an example:

enter image description here

st123
  • 246
  • 3
  • 14

1 Answers1

0

I suppose this is what you are looking for...

const count = (teamA, teamB) => teamB.map(B => teamA.filter(A => A<=B).length );

console.log(JSON.stringify( count([2,3,4], [3,5])) )    // [ 2,3 ]
console.log(JSON.stringify( count([1,4,2,4], [3,5])) )  // [ 2,4 ]
Mister Jojo
  • 20,093
  • 6
  • 21
  • 40
  • While that returns the same result for the given input, it is most likely not what OP is asking about. Have a look at their code. Their logic is completely different. – str Dec 01 '20 at 14:29
  • @str that's why I ask him if this answer is what he is looking for or not! this answer is to be understood as a question with an example . And there is no logic in his code, I also asked him for more explanation in a comment ... – Mister Jojo Dec 01 '20 at 14:33
  • @MisterJojo I posted an example test cases the question provided to be clearer. Sorry for being vague I'm just trying to communicate the info that was given to me – st123 Dec 01 '20 at 22:57
  • @MisterJojo still no luck, but thank you for the help! – st123 Dec 02 '20 at 01:39
  • @st123 How that ? this is exactly the logic you show – Mister Jojo Dec 02 '20 at 01:52