Challenge: Club Entry System
This challenge will test your skills in implementing function composition in JavaScript.
We'll cover the following
Problem statement #
A security guard at the club needs to ensure that only customers
over or equal to the age of 18 enter the club.
Here customers
is an array of objects such that each customer object has an age
and name
property.
The guard needs the name
s of the customers who can enter the club. He can make use of two functions:
-
filter
-
map
Both of these are given to you in the testing widget.
Your task is to write a funcCompose
function, which will be a higher-order function that takes multiple functions and composes them. In this case, it should compose the two functions mentioned above.
Here is an example of what we want to achieve:
funcCompose(func1, func2)(input)
Test your implementation by calling the compose function in the test
function and then return the final answer, the name
s of customers that can enter the club.
Input #
customers
array passed into the test
function
Output #
funcCompose
called and the name
s of the customers that can enter the club returned
Sample input #
const customers = [
{ name: "Hermoine", age: 15 },
{ name: "Ron", age: 18 },
{ name: "Harry", age: 24 },
]
Sample output #
["Ron", "Harry"]
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.