I am attempting to understand how to better use functional programming to achieve cleanliness of code. Ideally, I'd like to use ramda.js for this, but I'm open to any other functional library.
I have two parameters:
emailSearchTermString[{ value: 'ACTIVE'}, { value: 'INACTIVE'}]Array of Objects
I have an array I desire to filter by the two parameters above:
[
{
email: '[email protected]',
status: 'ACTIVE'
},
{
email: '[email protected]',
status: 'INACTIVE'
},
]
How would one use a pure function that leverages two inputs to effectively filter through an array of objects?
EDIT: Great followup questions:
For now I have used partial filtering using the search term:
searchTerm ? userList.filter(user => user.email.toLowerCase()
.indexOf(searchTerm.toLowerCase()) > -1) : userList
userList represents the array of objects, while my searchTerm ternary function looks for partial matches. My goal is to extend this function to additionally take an array of status' -- and I'd like to do so in a clean, functional style that is easy to read -- something outside my current skill level. To summarize, the criteria is:
- Partial match via email input to email property in userList
- Full match in status
- both parameters need to be satisfied
emailSearchTerm? What is the desired result? Which all fields need to be looked up? What is the criteria that governs whether there is a match or not?