Created
September 18, 2017 15:34
-
-
Save DrinKaziu/22b4df74c2047abbd057bbf88a0aac04 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/jogetof
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
| <!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 makeStudentsReport(data) { | |
| var results = []; | |
| for (var i=0; i<data.length; i++) { | |
| var item = data[i]; | |
| results.push(item.name + ': ' + item.grade); | |
| } | |
| return results; | |
| } | |
| /* From here down, you are not expected to | |
| understand.... for now :) | |
| Nothing to see here! | |
| */ | |
| // tests | |
| function testIt() { | |
| var testData = [ | |
| {name: 'Jane Doe', grade: 'A'}, | |
| {name: 'John Dough', grade: 'B'}, | |
| {name: 'Jill Do', grade: 'A'} | |
| ]; | |
| var expectations = [ | |
| 'Jane Doe: A', | |
| 'John Dough: B', | |
| 'Jill Do: A' | |
| ]; | |
| var results = makeStudentsReport(testData); | |
| if (!(results && results instanceof Array)) { | |
| console.error( | |
| 'FAILURE: `makeStudentsReport` must return an array'); | |
| return | |
| } | |
| if (results.length !== testData.length) { | |
| console.error( | |
| 'FAILURE: test data had length of ' + testData.length + | |
| ' but `makeStudentsReport` returned array of length ' + results.length); | |
| return | |
| } | |
| for (var i=0; i < expectations.length; i++) { | |
| var expect = expectations[i]; | |
| if (!results.find(function(item) { | |
| return item === expect; | |
| })) { | |
| console.error( | |
| 'FAILURE: `makeStudentsReport` is not ' + | |
| 'producing expected strings' | |
| ); | |
| return | |
| } | |
| } | |
| console.log('SUCCESS: `makeStudentsReport` is working'); | |
| } | |
| testIt(); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">function makeStudentsReport(data) { | |
| var results = []; | |
| for (var i=0; i<data.length; i++) { | |
| var item = data[i]; | |
| results.push(item.name + ': ' + item.grade); | |
| } | |
| return results; | |
| } | |
| /* From here down, you are not expected to | |
| understand.... for now :) | |
| Nothing to see here! | |
| */ | |
| // tests | |
| function testIt() { | |
| var testData = [ | |
| {name: 'Jane Doe', grade: 'A'}, | |
| {name: 'John Dough', grade: 'B'}, | |
| {name: 'Jill Do', grade: 'A'} | |
| ]; | |
| var expectations = [ | |
| 'Jane Doe: A', | |
| 'John Dough: B', | |
| 'Jill Do: A' | |
| ]; | |
| var results = makeStudentsReport(testData); | |
| if (!(results && results instanceof Array)) { | |
| console.error( | |
| 'FAILURE: `makeStudentsReport` must return an array'); | |
| return | |
| } | |
| if (results.length !== testData.length) { | |
| console.error( | |
| 'FAILURE: test data had length of ' + testData.length + | |
| ' but `makeStudentsReport` returned array of length ' + results.length); | |
| return | |
| } | |
| for (var i=0; i < expectations.length; i++) { | |
| var expect = expectations[i]; | |
| if (!results.find(function(item) { | |
| return item === expect; | |
| })) { | |
| console.error( | |
| 'FAILURE: `makeStudentsReport` is not ' + | |
| 'producing expected strings' | |
| ); | |
| return | |
| } | |
| } | |
| console.log('SUCCESS: `makeStudentsReport` is working'); | |
| } | |
| testIt(); | |
| </script></body> | |
| </html> |
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 makeStudentsReport(data) { | |
| var results = []; | |
| for (var i=0; i<data.length; i++) { | |
| var item = data[i]; | |
| results.push(item.name + ': ' + item.grade); | |
| } | |
| return results; | |
| } | |
| /* From here down, you are not expected to | |
| understand.... for now :) | |
| Nothing to see here! | |
| */ | |
| // tests | |
| function testIt() { | |
| var testData = [ | |
| {name: 'Jane Doe', grade: 'A'}, | |
| {name: 'John Dough', grade: 'B'}, | |
| {name: 'Jill Do', grade: 'A'} | |
| ]; | |
| var expectations = [ | |
| 'Jane Doe: A', | |
| 'John Dough: B', | |
| 'Jill Do: A' | |
| ]; | |
| var results = makeStudentsReport(testData); | |
| if (!(results && results instanceof Array)) { | |
| console.error( | |
| 'FAILURE: `makeStudentsReport` must return an array'); | |
| return | |
| } | |
| if (results.length !== testData.length) { | |
| console.error( | |
| 'FAILURE: test data had length of ' + testData.length + | |
| ' but `makeStudentsReport` returned array of length ' + results.length); | |
| return | |
| } | |
| for (var i=0; i < expectations.length; i++) { | |
| var expect = expectations[i]; | |
| if (!results.find(function(item) { | |
| return item === expect; | |
| })) { | |
| console.error( | |
| 'FAILURE: `makeStudentsReport` is not ' + | |
| 'producing expected strings' | |
| ); | |
| return | |
| } | |
| } | |
| console.log('SUCCESS: `makeStudentsReport` is working'); | |
| } | |
| testIt(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment