Guest User

Untitled

a guest
Oct 24th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. function divisibleBy5(array) {
  2. // your code here
  3. return array.find(num => num % 5 === 0);
  4. }
  5.  
  6.  
  7. /* From here down, you are not expected to
  8. understand.... for now :)
  9.  
  10.  
  11. Nothing to see here!
  12.  
  13. */
  14.  
  15.  
  16. // tests
  17.  
  18. function testFunctionWorks(fn, input, expected) {
  19.  
  20. if (fn(input) === expected) {
  21. console.log('SUCCESS: `' + fn.name + '` works on `[' + input + ']`');
  22. return true;
  23. }
  24. else {
  25. console.error(
  26. 'FAILURE: `' + fn.name + '([' + input + '])` should be ' + expected +
  27. ' but was ' + fn(input)
  28. );
  29. return false;
  30. }
  31. }
  32.  
  33. function runTests() {
  34.  
  35. const input1 = [13, 22, 4, 47, 15, 35, 82];
  36. const result1 = 15;
  37. const input2 = [25, 20, 15, 10, 5];
  38. const result2 = 25;
  39.  
  40. const testResults = [
  41. testFunctionWorks(divisibleBy5, input1, result1),
  42. testFunctionWorks(divisibleBy5, input2, result2),
  43. ];
  44.  
  45.  
  46.  
  47. const numPassing = testResults.filter(function(result){ return result; }).length;
  48. console.log(numPassing + ' out of ' + testResults.length + ' tests passing.');
  49. }
  50.  
  51. runTests();
Add Comment
Please, Sign In to add comment