Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. This is a small utility designed to take an array of people objects, each with name, age and gender as well as an optional set of rules for filtering those objects, and return the filtered list, grouped by the genders of the people.
  2.  
  3. By default, if no custom rules are passed in, only people between the ages of 30 and 40 will be returned.
  4.  
  5. Run and read the tests to see different inputs and outputs.
  6.  
  7. Here's an example:
  8.  
  9. ``` javascript
  10. const peopleFilter = require('../src/people-filter');
  11. const youngerMalePeople = [
  12. {
  13. name: 'Dave',
  14. age: 25,
  15. gender: 'Male',
  16. },
  17. ]
  18. const olderMalePeople = [
  19. {
  20. name: 'Josh',
  21. age: 30,
  22. gender: 'Male',
  23. },
  24. {
  25. name: 'John',
  26. age: 31,
  27. gender: 'Male'
  28. },
  29. ]
  30. const malePeople = [
  31. ...olderMalePeople,
  32. ...youngerMalePeople,
  33. ];
  34.  
  35. const filteredPeopleDefaultRules = peopleFilter(malePeople);
  36.  
  37. console.log(JSON.stringify(filteredPeopleDefaultRules));
  38. // Will be the 'olderMalePeople' array
  39.  
  40. const customRules = ['personToFilter.age >= 20 && personToFilter.age < 30'];
  41. const youngerPeople = peopleFilter(testPeopleToFilter, customRules);
  42.  
  43. console.log(JSON.stringify(youngerPeople));
  44. // Will be the 'youngerMalePeople' array
  45. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement