Skip to content

Instantly share code, notes, and snippets.

Created June 15, 2017 06:33
Show Gist options
  • Save anonymous/e49ca2f4949cc360ee3aa9830a9b0a21 to your computer and use it in GitHub Desktop.
Save anonymous/e49ca2f4949cc360ee3aa9830a9b0a21 to your computer and use it in GitHub Desktop.
enrollJS created by dtstanley - https://repl.it/G9N6/210
var studentData = [
{
name: 'Tim',
status: 'Current student',
course: 'Biology'
},
{
name: 'Sue',
status: 'Withdrawn',
course: 'Mathematics'
},
{
name: 'Liz',
status: 'On leave',
course: 'Computer science'
}
];
function enrollInSummerSchool(students) {
var myArray =[];
for (var i=0;i<students.length;i++){
myArray.push(
{name:students[i].name,
status:'In Summer school',
course:students[i].course
})
}
return myArray;
}
/* From here down, you are not expected to understand.... for now :)
Nothing to see here!
*/
// tests
function testIt() {
var testData = [
{
name: 'Burt',
status: 'Playing hooky',
course: 'Biology'
},
{
name: 'Melanie',
status: 'Sick',
course: 'Mathematics'
},
{
name: 'Leonard',
status: 'AWOL',
course: 'Computer science'
}
];
var results = enrollInSummerSchool(testData);
if (!(results && results instanceof Array)) {
console.error('FAILURE: `enrollSummerSchool` must return an array');
return
}
for (var i=0; i<testData.length; i++) {
var result = results.find(function(_result) {
return (
_result.name === testData[i].name &&
_result.course === testData[i].course &&
_result.status === 'In Summer school');
});
if (!result) {
console.error(
'FAILURE: `enrollSummerSchool` should return ' +
'original key/value pairs for each student, and ' +
'update `status` to "In Summer school"');
return
}
}
console.info('SUCCESS: `enrollSummerSchool` is working');
}
testIt();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment