samfrancisco

Software Engineering Coding Challenge 1 (Javascript)

Oct 24th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Requirements:
  3.  * Given an array "people", write:
  4.  * 1. A function "listByGender" that accepts "gender" and returns an array of people that falls under the given gender; and
  5.  * 2. A function "groupByDepartment" that returns people grouped by their department.
  6.  *
  7.  * Write your solution without using any libraries and use ES6 or above as much as possible.
  8.  */
  9.  
  10. const people = [
  11.   {
  12.     name: 'Arisa',
  13.     department: 'BP',
  14.     gender: 'F'
  15.   },
  16.   {
  17.     name: 'Ham',
  18.     department: 'IT',
  19.     gender: 'F'
  20.   },
  21.   {
  22.     name: 'Alice',
  23.     department: 'IT',
  24.     gender: 'F'
  25.   },
  26.   {
  27.     name: 'Anna',
  28.     department: 'DA',
  29.     gender: 'F'
  30.   },
  31.   {
  32.     name: 'Larry',
  33.     department: 'Sales',
  34.     gender: 'M'
  35.   },
  36.   {
  37.     name: 'Ria',
  38.     department: 'Sales',
  39.     gender: 'F'
  40.   },
  41.   {
  42.     name: 'JD',
  43.     department: 'Sales',
  44.     gender: 'M'
  45.   },
  46.   {
  47.     name: 'Thor',
  48.     department: 'Sales',
  49.     gender: 'M'
  50.   },
  51.   {
  52.     name: 'Karl',
  53.     department: 'Sales',
  54.     gender: 'M'
  55.   },
  56.   {
  57.     name: 'Rachel',
  58.     department: 'Sales',
  59.     gender: 'F'
  60.   }
  61. ];
  62.  
  63. function listByGender(gender) {}
  64.  
  65. function groupByDepartment() {}
  66.  
  67. // Test:
  68. listByGender('M'); // Output: Includes Larry, JD, Thor, and Karl
  69. listByGender('F'); // Output: Includes Arisa, Ham, Alice, Anna, Ria, and Rachel
  70. groupByDepartment(); // Output: People grouped by their department
Advertisement
Add Comment
Please, Sign In to add comment