Created
April 28, 2017 00:41
-
-
Save dtstanley/54618f05feec2dd29eeb9748fbac05cd to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/rerenil
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 minusLastItem(array) { | |
return array.slice(0,(array.length-1)); | |
} | |
function copyFirstHalf(array) { | |
return array.slice(0,array.length/2); | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
// tests | |
function testFunctionWorks(fn, input, expected) { | |
var result = fn(input); | |
if ( | |
result && result.length === expected.length && | |
result.every(function(item) { | |
return expected.indexOf(item) > -1; | |
})) { | |
console.log('SUCCESS: `' + fn.name + '` works!'); | |
return true; | |
} else { | |
console.error('FAILURE: `' + fn.name + '` is not working'); | |
return false; | |
} | |
} | |
function runTests() { | |
var list = ["red bull", "monster", "amp", "rockstar", "full throttle", "kickstart"]; | |
var result1 = ["red bull", "monster", "amp", "rockstar", "full throttle"]; | |
var result2 = ["red bull", "monster", "amp"]; | |
var testResults = [ | |
testFunctionWorks(minusLastItem, list, result1), | |
testFunctionWorks(copyFirstHalf, list, result2), | |
]; | |
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 minusLastItem(array) { | |
return array.slice(0,(array.length-1)); | |
} | |
function copyFirstHalf(array) { | |
return array.slice(0,array.length/2); | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
// tests | |
function testFunctionWorks(fn, input, expected) { | |
var result = fn(input); | |
if ( | |
result && result.length === expected.length && | |
result.every(function(item) { | |
return expected.indexOf(item) > -1; | |
})) { | |
console.log('SUCCESS: `' + fn.name + '` works!'); | |
return true; | |
} else { | |
console.error('FAILURE: `' + fn.name + '` is not working'); | |
return false; | |
} | |
} | |
function runTests() { | |
var list = ["red bull", "monster", "amp", "rockstar", "full throttle", "kickstart"]; | |
var result1 = ["red bull", "monster", "amp", "rockstar", "full throttle"]; | |
var result2 = ["red bull", "monster", "amp"]; | |
var testResults = [ | |
testFunctionWorks(minusLastItem, list, result1), | |
testFunctionWorks(copyFirstHalf, list, result2), | |
]; | |
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 minusLastItem(array) { | |
return array.slice(0,(array.length-1)); | |
} | |
function copyFirstHalf(array) { | |
return array.slice(0,array.length/2); | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
// tests | |
function testFunctionWorks(fn, input, expected) { | |
var result = fn(input); | |
if ( | |
result && result.length === expected.length && | |
result.every(function(item) { | |
return expected.indexOf(item) > -1; | |
})) { | |
console.log('SUCCESS: `' + fn.name + '` works!'); | |
return true; | |
} else { | |
console.error('FAILURE: `' + fn.name + '` is not working'); | |
return false; | |
} | |
} | |
function runTests() { | |
var list = ["red bull", "monster", "amp", "rockstar", "full throttle", "kickstart"]; | |
var result1 = ["red bull", "monster", "amp", "rockstar", "full throttle"]; | |
var result2 = ["red bull", "monster", "amp"]; | |
var testResults = [ | |
testFunctionWorks(minusLastItem, list, result1), | |
testFunctionWorks(copyFirstHalf, list, result2), | |
]; | |
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