Guest User

Untitled

a guest
Apr 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. const studentData = [
  2. {
  3. name: 'Tim',
  4. status: 'Current student',
  5. course: 'Biology',
  6. },
  7. {
  8. name: 'Sue',
  9. status: 'Withdrawn',
  10. course: 'Mathematics',
  11. },
  12. {
  13. name: 'Liz',
  14. status: 'On leave',
  15. course: 'Computer science',
  16. },
  17. ];
  18.  
  19. function enrollInSummerSchool(students) {
  20. return students.map(student => {
  21. return {
  22. name: student.name,
  23. status: 'In Summer school',
  24. course: student.course,
  25. };
  26. });
  27. }
  28.  
  29. /* From here down, you are not expected to understand.... for now :)
  30. Nothing to see here!
  31.  
  32. */
  33.  
  34. // tests
  35.  
  36. function testIt() {
  37. var testData = [
  38. {
  39. name: 'Burt',
  40. status: 'Playing hooky',
  41. course: 'Biology',
  42. },
  43. {
  44. name: 'Melanie',
  45. status: 'Sick',
  46. course: 'Mathematics',
  47. },
  48. {
  49. name: 'Leonard',
  50. status: 'AWOL',
  51. course: 'Computer science',
  52. },
  53. ];
  54.  
  55. var results = enrollInSummerSchool(testData);
  56.  
  57. if (!(results && results instanceof Array)) {
  58. console.error('FAILURE: `enrollSummerSchool` must return an array');
  59. return;
  60. }
  61. var result = testData.every(function(student) {
  62. var match = results.find(function(_student) {
  63. return (
  64. _student.name === student.name &&
  65. _student.course === student.course &&
  66. _student.status.toLowerCase() === 'in summer school'
  67. );
  68. });
  69. return match !== undefined;
  70. });
  71. if (!result) {
  72. console.error(
  73. 'FAILURE: `enrollSummerSchool` should return ' +
  74. 'original key/value pairs for each student, and ' +
  75. 'update `status` to "In Summer school": ' +
  76. JSON.stringify(results)
  77. );
  78. } else {
  79. console.info('SUCCESS: `enrollSummerSchool` is working');
  80. }
  81. }
  82.  
  83. testIt();
Add Comment
Please, Sign In to add comment