Created
December 12, 2018 07:13
-
-
Save zempo/e595302c2a8231a61fce85e30dd26940 to your computer and use it in GitHub Desktop.
Make student reports drill created by zempo1 - https://repl.it/@zempo1/Make-student-reports-drill
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 makeStudentsReport(data) { | |
let report = []; | |
for (i = 0; i < data.length; i++) { | |
let student = data[i]; | |
report.push(`${student.name}: ${student.grade}`); | |
} | |
return report; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
// tests | |
function testIt() { | |
const testData = [ | |
{ name: 'Jane Doe', grade: 'A' }, | |
{ name: 'John Dough', grade: 'B' }, | |
{ name: 'Jill Do', grade: 'A' }, | |
]; | |
const expectations = ['Jane Doe: A', 'John Dough: B', 'Jill Do: A']; | |
const 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 (let i = 0; i < expectations.length; i++) { | |
let 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
Starred b/c includes jQuery