Last active
May 13, 2017 04:03
-
-
Save GeoDoo/d721c1baea55aeec6c474d8a2b79be93 to your computer and use it in GitHub Desktop.
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 average(numbers) { | |
return sum(numbers) / numbers.length; | |
} | |
function sum(numbers) { | |
return numbers.reduce(function(a, b) { | |
return a + b; | |
}); | |
} | |
function assertAverageEqual(actual, expected, testName) { | |
if (actual === expected) { | |
console.log('passed'); | |
} else { | |
console.log('FAILED: ' + testName + ', expected ' + actual + ' to be ' + expected); | |
} | |
} | |
function assertSumEqual(actual, expected, testName) { | |
if (actual === expected) { | |
console.log('passed'); | |
} else { | |
console.log('FAILED: ' + testName + ', expected ' + actual + ' to be ' + expected); | |
} | |
} | |
assertAverageEqual(average([1,2,3,4]), 2.5, 'Average function'); | |
assertSumEqual(sum([1,2,3,4]), 10, 'Sum function'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment