Created
          March 13, 2018 01:44 
        
      - 
      
 - 
        
Save liseferguson/a33d57ee4e5b0de3a7b0835a8e4dad55 to your computer and use it in GitHub Desktop.  
    index.js
  
        
  
    
      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 findLength(array) { | |
| return array.length; | |
| } | |
| function accessLastItem(array) { | |
| return array[array.length - 1]; | |
| } | |
| /* In the 2nd function, why is the array before the [array.length - 1] necessary? | |
| /* 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 list = [1, 4, 9, 16, 25]; | |
| const originalList = [1, 4, 9, 16, 25]; | |
| const length = 5; | |
| const lastItem = 25; | |
| const testResults = [ | |
| testFunctionWorks(findLength, list, length), | |
| testFunctionWorks(accessLastItem, list, lastItem), | |
| ]; | |
| 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
  
            
https://repl.it/@liseferguson/Adding-array-items-drills