Challenge: Calculate Score
This challenge will test your skills in implementing the reduce function in JavaScript.
We'll cover the following
Problem statement #
In this challenge, you have to implement the function boySum
that takes the parameter records
. Here records
is an array of objects that contains two properties, gender
and value
. The gender
can either be BOYS
or GIRLS
. Your task is to return the sum of all the value
s that have BOYS
as the gender.
Input #
The array records
containing objects
Output #
The sum of all the value
s of the objects which have BOYS
as the gender.
Sample input #
const records = [
{
value: 24,
gender: "BOYS"
},
{
value: 42,
gender: "BOYS"
},
{
value: 85,
gender: "GIRLS"
},
{
value: 12,
gender: "GIRLS"
},
{
value: 10,
gender: "BOYS"
}
]
Sample output #
76
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.