Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!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 firstFourItems(array) {
- // your code goes here
- }
- function lastThreeItems(array) {
- // your code goes 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) {
- 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"];
- var result1 = ["red bull", "monster", "amp", "rockstar"];
- var result2 = ["amp", "rockstar", "full throttle"];
- var testResults = [
- testFunctionWorks(firstFourItems, list, result1),
- testFunctionWorks(lastThreeItems, 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 firstFourItems(array) {
- // your code goes here
- }
- function lastThreeItems(array) {
- // your code goes 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) {
- 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"];
- var result1 = ["red bull", "monster", "amp", "rockstar"];
- var result2 = ["amp", "rockstar", "full throttle"];
- var testResults = [
- testFunctionWorks(firstFourItems, list, result1),
- testFunctionWorks(lastThreeItems, list, result2),
- ];
- var numPassing = testResults.filter(function(result){ return result; }).length;
- console.log(numPassing + ' out of ' + testResults.length + ' tests passing.');
- }
- runTests();
- </script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement