Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 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. function firstFourItems(array) {
  12. // your code goes here
  13. }
  14.  
  15.  
  16. function lastThreeItems(array) {
  17. // your code goes here
  18. }
  19.  
  20.  
  21.  
  22.  
  23. /* From here down, you are not expected to
  24. understand.... for now :)
  25.  
  26.  
  27. Nothing to see here!
  28.  
  29. */
  30.  
  31.  
  32. // tests
  33.  
  34. function testFunctionWorks(fn, input, expected) {
  35.  
  36. var result = fn(input);
  37. if (
  38. result && result.length === expected.length &&
  39. result.every(function(item) {
  40. return expected.indexOf(item) > -1;
  41. })) {
  42. console.log('SUCCESS: `' + fn.name + '` works!')
  43. return true;
  44. }
  45. else {
  46. console.error('FAILURE: `' + fn.name + '` is not working')
  47. return false;
  48. }
  49. }
  50.  
  51. function runTests() {
  52.  
  53. var list = ["red bull", "monster", "amp", "rockstar", "full throttle"];
  54. var result1 = ["red bull", "monster", "amp", "rockstar"];
  55. var result2 = ["amp", "rockstar", "full throttle"];
  56.  
  57. var testResults = [
  58. testFunctionWorks(firstFourItems, list, result1),
  59. testFunctionWorks(lastThreeItems, list, result2),
  60. ];
  61.  
  62.  
  63. var numPassing = testResults.filter(function(result){ return result; }).length;
  64. console.log(numPassing + ' out of ' + testResults.length + ' tests passing.');
  65. }
  66.  
  67. runTests();
  68. </script>
  69.  
  70.  
  71.  
  72. <script id="jsbin-source-javascript" type="text/javascript">
  73. function firstFourItems(array) {
  74. // your code goes here
  75. }
  76.  
  77.  
  78. function lastThreeItems(array) {
  79. // your code goes here
  80. }
  81.  
  82.  
  83.  
  84.  
  85. /* From here down, you are not expected to
  86. understand.... for now :)
  87.  
  88.  
  89. Nothing to see here!
  90.  
  91. */
  92.  
  93.  
  94. // tests
  95.  
  96. function testFunctionWorks(fn, input, expected) {
  97.  
  98. var result = fn(input);
  99. if (
  100. result && result.length === expected.length &&
  101. result.every(function(item) {
  102. return expected.indexOf(item) > -1;
  103. })) {
  104. console.log('SUCCESS: `' + fn.name + '` works!')
  105. return true;
  106. }
  107. else {
  108. console.error('FAILURE: `' + fn.name + '` is not working')
  109. return false;
  110. }
  111. }
  112.  
  113. function runTests() {
  114.  
  115. var list = ["red bull", "monster", "amp", "rockstar", "full throttle"];
  116. var result1 = ["red bull", "monster", "amp", "rockstar"];
  117. var result2 = ["amp", "rockstar", "full throttle"];
  118.  
  119. var testResults = [
  120. testFunctionWorks(firstFourItems, list, result1),
  121. testFunctionWorks(lastThreeItems, list, result2),
  122. ];
  123.  
  124.  
  125. var numPassing = testResults.filter(function(result){ return result; }).length;
  126. console.log(numPassing + ' out of ' + testResults.length + ' tests passing.');
  127. }
  128.  
  129. runTests();
  130. </script></body>
  131. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement