Created
March 15, 2018 03:06
-
-
Save liseferguson/51aca52eeb533f8bda77103d12741510 to your computer and use it in GitHub Desktop.
find drill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function divisibleBy5(array) { | |
| return array.find(function(num) { | |
| return num % 5 === 0; | |
| }); | |
| } | |
| /* From here down, you are not expected to | |
| understand.... for now :) | |
| Nothing to see here! | |
| */ | |
| // tests | |
| function testFunctionWorks(fn, input, expected) { | |
| if (fn(input) === expected) { | |
| console.log('SUCCESS: `' + fn.name + '` works on `[' + input + ']`'); | |
| return true; | |
| } else { | |
| console.error( | |
| 'FAILURE: `' + | |
| fn.name + | |
| '([' + | |
| input + | |
| '])` should be ' + | |
| expected + | |
| ' but was ' + | |
| fn(input) | |
| ); | |
| return false; | |
| } | |
| } | |
| function runTests() { | |
| const input1 = [13, 22, 4, 47, 15, 35, 82]; | |
| const result1 = 15; | |
| const input2 = [25, 20, 15, 10, 5]; | |
| const result2 = 25; | |
| const testResults = [ | |
| testFunctionWorks(divisibleBy5, input1, result1), | |
| testFunctionWorks(divisibleBy5, input2, result2), | |
| ]; | |
| const numPassing = testResults.filter(function(result) { | |
| return result; | |
| }).length; | |
| console.log(numPassing + ' out of ' + testResults.length + ' tests passing.'); | |
| } | |
| runTests(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment