Created
March 7, 2017 02:52
-
-
Save Mattteo1220/e48ff360b16fbf9e5c31445b84999d68 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/liqeyuz
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 greatestToLeast(array) { | |
// your code ges here | |
} | |
/* 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, index) { | |
return (index === 0 || result[index] < result[index-1]); | |
}) && | |
result.every(function(item) { | |
return expected.indexOf(item) > -1; | |
})) { | |
console.log('SUCCESS: `' + fn.name + '` works!') | |
return true; | |
} | |
else { | |
console.error('FAILURE: `' + fn.name + '([' + input + '])` should be ' + expected + | |
' but was ' + fn(input)) | |
return false; | |
} | |
} | |
function runTests() { | |
var input1 = [10, 3, 5, 22, 19]; | |
var result1 = [22, 19, 10, 5, 3]; | |
var input2 = [2, 4, 6, 8]; | |
var result2 = [8, 6, 4, 2]; | |
var testResults = [ | |
testFunctionWorks(greatestToLeast, input1, result1), | |
testFunctionWorks(greatestToLeast, input2, 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 greatestToLeast(array) { | |
// your code ges here | |
} | |
/* 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, index) { | |
return (index === 0 || result[index] < result[index-1]); | |
}) && | |
result.every(function(item) { | |
return expected.indexOf(item) > -1; | |
})) { | |
console.log('SUCCESS: `' + fn.name + '` works!') | |
return true; | |
} | |
else { | |
console.error('FAILURE: `' + fn.name + '([' + input + '])` should be ' + expected + | |
' but was ' + fn(input)) | |
return false; | |
} | |
} | |
function runTests() { | |
var input1 = [10, 3, 5, 22, 19]; | |
var result1 = [22, 19, 10, 5, 3]; | |
var input2 = [2, 4, 6, 8]; | |
var result2 = [8, 6, 4, 2]; | |
var testResults = [ | |
testFunctionWorks(greatestToLeast, input1, result1), | |
testFunctionWorks(greatestToLeast, input2, 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 greatestToLeast(array) { | |
// your code ges here | |
} | |
/* 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, index) { | |
return (index === 0 || result[index] < result[index-1]); | |
}) && | |
result.every(function(item) { | |
return expected.indexOf(item) > -1; | |
})) { | |
console.log('SUCCESS: `' + fn.name + '` works!') | |
return true; | |
} | |
else { | |
console.error('FAILURE: `' + fn.name + '([' + input + '])` should be ' + expected + | |
' but was ' + fn(input)) | |
return false; | |
} | |
} | |
function runTests() { | |
var input1 = [10, 3, 5, 22, 19]; | |
var result1 = [22, 19, 10, 5, 3]; | |
var input2 = [2, 4, 6, 8]; | |
var result2 = [8, 6, 4, 2]; | |
var testResults = [ | |
testFunctionWorks(greatestToLeast, input1, result1), | |
testFunctionWorks(greatestToLeast, input2, 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