Need help with a problem (functional programming)


Hello guys, I’ve been doing thejsway book and I’m currently at chapter 10 which talks about functional programming. The last problem they give you to practice is to refactor a code, I’ve been going at it for hours now and can’t seem to see how to refactor it. So I would like to know how would you do it, or show me how, cause right now I’m lost, heh.
I’ll link a codepen to the code they gave out, the code has to give out the same output in the console, you just have to use functions rather than what it shows now, any ideas?


To start with functions, I would recommend using two functions based on the CodePen you have shared-

  1. Use the jQuery filter() function on the students array to filter out the female students. That will help you get rid of the if condition inside your loop.
  2. Use the reduce() function to find the sum of the grades.

I’m sure there might be a lot more ways to refactor this, but these are the ones that I could think of right now. You can see it on JSFiddle here -


Thank you for your reply, I have a better understanding now