Filter one array using another

I am trying to write a function that prints out a list of all courses with a passing grade but cant’t figure out how. How may I implement that? (The minimum passing grade is 5.)

courses = [Math, Geography, Chemistry]
grades = [7, 3, 5]
(the grades[0] grade corresponds to the courses[0] course and so on.)

desired output:
Passed = Math, Chemistry.

What have you tried?

there are many possible ways… a loop, filter, forEach

I have tried using a filter but it didn’t work (though I was using it wrong since the filter parameter is not an index.)
It was something like courses.filter((x) => grades[x] >=5)

You should read more about filter and what arguments are available to it. x is not what you think it is.

1 Like