Guest User

Untitled

a guest
May 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. var studentData = [
  12. {
  13. name: 'Tim',
  14. status: 'Current student',
  15. course: 'Biology'
  16. },
  17. {
  18. name: 'Sue',
  19. status: 'Withdrawn',
  20. course: 'Mathematics'
  21. },
  22. {
  23. name: 'Liz',
  24. status: 'On leave',
  25. course: 'Computer science'
  26. }
  27. ];
  28.  
  29. function enrollInSummerSchool(students) {
  30. var studentData = [
  31. {
  32. name: 'Tim',
  33. status: 'Current student',
  34. course: 'Biology'
  35. },
  36. {
  37. name: 'Sue',
  38. status: 'Withdrawn',
  39. course: 'Mathematics'
  40. },
  41. {
  42. name: 'Liz',
  43. status: 'On leave',
  44. course: 'Computer science'
  45. }
  46. ];
  47.  
  48. function enrollInSummerSchool(students) {
  49. var data2 = [];
  50. students.forEach(function(student) {
  51. student.status = "In Summer school";
  52.  
  53. })
  54. return students;
  55.  
  56. }
  57.  
  58.  
  59. /* From here down, you are not expected to understand.... for now :)
  60. Nothing to see here!
  61.  
  62. */
  63.  
  64. // tests
  65.  
  66.  
  67. function testIt() {
  68. var testData = [
  69. {
  70. name: 'Burt',
  71. status: 'Playing hooky',
  72. course: 'Biology'
  73. },
  74. {
  75. name: 'Melanie',
  76. status: 'Sick',
  77. course: 'Mathematics'
  78. },
  79. {
  80. name: 'Leonard',
  81. status: 'AWOL',
  82. course: 'Computer science'
  83. }
  84. ];
  85.  
  86. var results = enrollInSummerSchool(testData);
  87.  
  88. if (!(results && results instanceof Array)) {
  89. console.error('FAILURE: `enrollSummerSchool` must return an array');
  90. return
  91. }
  92.  
  93. for (var i=0; i<testData.length; i++) {
  94. var result = results.find(function(_result) {
  95. return (
  96. _result.name === testData[i].name &&
  97. _result.course === testData[i].course &&
  98. _result.status === 'In Summer school');
  99. });
  100. if (!result) {
  101. console.error(
  102. 'FAILURE: `enrollSummerSchool` should return ' +
  103. 'original key/value pairs for each student, and ' +
  104. 'update `status` to "In Summer school"');
  105. return
  106. }
  107. }
  108. console.info('SUCCESS: `enrollSummerSchool` is working');
  109. }
  110.  
  111. testIt();
  112. </script>
  113.  
  114.  
  115.  
  116. <script id="jsbin-source-javascript" type="text/javascript">var studentData = [
  117. {
  118. name: 'Tim',
  119. status: 'Current student',
  120. course: 'Biology'
  121. },
  122. {
  123. name: 'Sue',
  124. status: 'Withdrawn',
  125. course: 'Mathematics'
  126. },
  127. {
  128. name: 'Liz',
  129. status: 'On leave',
  130. course: 'Computer science'
  131. }
  132. ];
  133.  
  134. function enrollInSummerSchool(students) {
  135. var studentData = [
  136. {
  137. name: 'Tim',
  138. status: 'Current student',
  139. course: 'Biology'
  140. },
  141. {
  142. name: 'Sue',
  143. status: 'Withdrawn',
  144. course: 'Mathematics'
  145. },
  146. {
  147. name: 'Liz',
  148. status: 'On leave',
  149. course: 'Computer science'
  150. }
  151. ];
  152.  
  153. function enrollInSummerSchool(students) {
  154. var data2 = [];
  155. students.forEach(function(student) {
  156. student.status = "In Summer school";
  157.  
  158. })
  159. return students;
  160.  
  161. }
  162.  
  163.  
  164. /* From here down, you are not expected to understand.... for now :)
  165. Nothing to see here!
  166.  
  167. */
  168.  
  169. // tests
  170.  
  171.  
  172. function testIt() {
  173. var testData = [
  174. {
  175. name: 'Burt',
  176. status: 'Playing hooky',
  177. course: 'Biology'
  178. },
  179. {
  180. name: 'Melanie',
  181. status: 'Sick',
  182. course: 'Mathematics'
  183. },
  184. {
  185. name: 'Leonard',
  186. status: 'AWOL',
  187. course: 'Computer science'
  188. }
  189. ];
  190.  
  191. var results = enrollInSummerSchool(testData);
  192.  
  193. if (!(results && results instanceof Array)) {
  194. console.error('FAILURE: `enrollSummerSchool` must return an array');
  195. return
  196. }
  197.  
  198. for (var i=0; i<testData.length; i++) {
  199. var result = results.find(function(_result) {
  200. return (
  201. _result.name === testData[i].name &&
  202. _result.course === testData[i].course &&
  203. _result.status === 'In Summer school');
  204. });
  205. if (!result) {
  206. console.error(
  207. 'FAILURE: `enrollSummerSchool` should return ' +
  208. 'original key/value pairs for each student, and ' +
  209. 'update `status` to "In Summer school"');
  210. return
  211. }
  212. }
  213. console.info('SUCCESS: `enrollSummerSchool` is working');
  214. }
  215.  
  216. testIt();</script></body>
  217. </html>
Add Comment
Please, Sign In to add comment