Last active
March 31, 2017 03:39
-
-
Save JNaeemGitonga/0ecfd2fa1933504d701081ba7c7c2b67 to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/geherul
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function findLength(array) { | |
return array.length; | |
} | |
function accessLastItem(array) { | |
return array.pop();} | |
/* I NAILED THIS ONE | |
*/ | |
// 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() { | |
var list = [1, 4, 9, 16, 25]; | |
var originalList = [1, 4, 9, 16, 25]; | |
var length = 5; | |
var lastItem = 25; | |
var testResults = [ | |
testFunctionWorks(findLength, list, length), | |
testFunctionWorks(accessLastItem, list, lastItem), | |
]; | |
var numPassing = testResults.filter(function(result){ return result; }).length; | |
console.log(numPassing + ' out of ' + testResults.length + ' tests passing.'); | |
} | |
runTests(); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function findLength(array) { | |
return array.length; | |
} | |
function accessLastItem(array) { | |
return array.pop();} | |
/* I NAILED THIS ONE | |
*/ | |
// 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() { | |
var list = [1, 4, 9, 16, 25]; | |
var originalList = [1, 4, 9, 16, 25]; | |
var length = 5; | |
var lastItem = 25; | |
var testResults = [ | |
testFunctionWorks(findLength, list, length), | |
testFunctionWorks(accessLastItem, list, lastItem), | |
]; | |
var numPassing = testResults.filter(function(result){ return result; }).length; | |
console.log(numPassing + ' out of ' + testResults.length + ' tests passing.'); | |
} | |
runTests();</script></body> | |
</html> |
This file contains 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.pop();} | |
/* I NAILED THIS ONE | |
*/ | |
// 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() { | |
var list = [1, 4, 9, 16, 25]; | |
var originalList = [1, 4, 9, 16, 25]; | |
var length = 5; | |
var lastItem = 25; | |
var testResults = [ | |
testFunctionWorks(findLength, list, length), | |
testFunctionWorks(accessLastItem, list, lastItem), | |
]; | |
var 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