Skip to content

Instantly share code, notes, and snippets.

@zempo
Created December 12, 2018 07:13
Show Gist options
  • Save zempo/e595302c2a8231a61fce85e30dd26940 to your computer and use it in GitHub Desktop.
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
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();
@zempo
Copy link
Author

zempo commented Dec 12, 2018

Starred b/c includes jQuery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment