Guest User

Untitled

a guest
Dec 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. function divisibleBy5(array) {
  2. return array.find(function(num) {
  3. return 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. // tests
  16.  
  17. function testFunctionWorks(fn, input, expected) {
  18. if (fn(input) === expected) {
  19. console.log('SUCCESS: `' + fn.name + '` works on `[' + input + ']`');
  20. return true;
  21. } else {
  22. console.error(
  23. 'FAILURE: `' +
  24. fn.name +
  25. '([' +
  26. input +
  27. '])` should be ' +
  28. expected +
  29. ' but was ' +
  30. fn(input)
  31. );
  32. return false;
  33. }
  34. }
  35.  
  36. function runTests() {
  37. const input1 = [13, 22, 4, 47, 15, 35, 82];
  38. const result1 = 15;
  39. const input2 = [25, 20, 15, 10, 5];
  40. const result2 = 25;
  41.  
  42. const testResults = [
  43. testFunctionWorks(divisibleBy5, input1, result1),
  44. testFunctionWorks(divisibleBy5, input2, result2),
  45. ];
  46.  
  47. const numPassing = testResults.filter(function(result) {
  48. return result;
  49. }).length;
  50. console.log(numPassing + ' out of ' + testResults.length + ' tests passing.');
  51. }
  52.  
  53. runTests();
Add Comment
Please, Sign In to add comment