Guest User

Untitled

a guest
Dec 14th, 2017
80
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.  
  30.  
  31. /* From here down, you are not expected to understand.... for now :)
  32. Nothing to see here!
  33.  
  34. */
  35.  
  36. // tests
  37.  
  38. function testIt() {
  39. var testData = [
  40. {
  41. name: 'Burt',
  42. status: 'Playing hooky',
  43. course: 'Biology',
  44. },
  45. {
  46. name: 'Melanie',
  47. status: 'Sick',
  48. course: 'Mathematics',
  49. },
  50. {
  51. name: 'Leonard',
  52. status: 'AWOL',
  53. course: 'Computer science',
  54. },
  55. ];
  56.  
  57. var results = enrollInSummerSchool(testData);
  58.  
  59. if (!(results && results instanceof Array)) {
  60. console.error('FAILURE: `enrollSummerSchool` must return an array');
  61. return;
  62. }
  63. var result = testData.every(function(student) {
  64. var match = results.find(function(_student) {
  65. return (
  66. _student.name === student.name &&
  67. _student.course === student.course &&
  68. _student.status.toLowerCase() === 'in summer school'
  69. );
  70. });
  71. return match !== undefined;
  72. });
  73. if (!result) {
  74. console.error(
  75. 'FAILURE: `enrollSummerSchool` should return ' +
  76. 'original key/value pairs for each student, and ' +
  77. 'update `status` to "In Summer school": ' +
  78. JSON.stringify(results)
  79. );
  80. } else {
  81. console.info('SUCCESS: `enrollSummerSchool` is working');
  82. }
  83. }
  84.  
  85. testIt();
Add Comment
Please, Sign In to add comment