Skip to content

Instantly share code, notes, and snippets.

@elliotkim916
Created October 13, 2017 03:15
Show Gist options
  • Save elliotkim916/c92ce5439335b6b0a9a97b8aec524073 to your computer and use it in GitHub Desktop.
Save elliotkim916/c92ce5439335b6b0a9a97b8aec524073 to your computer and use it in GitHub Desktop.
Object Drills 2
const 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) {
// your code here
var array = [];
for (var i = 0; i < students.length; i++) {
students[i].status = 'In Summer school';
array.push(students[i]);
} return array;
}
const scratchData = [
{id: 22, foo: 'bar'},
{id: 28, foo: 'bizz'},
{id: 19, foo: 'bazz'}
];
function findById(items, idNum) {
// your code here
for (let i = 0; i < items.length; i++) {
if (idNum === items[i].id) {
return items[i];
}
}
}
function makeStudentsReport(data) {
// your code here
var array = [];
for (let i = 0; i < data.length; i++) {
array.push(data[i].name + ': ' + data[i].grade);
}
return array;
}
// running the function with `objectA` and `expectedKeys`
// should return `true`
const objectA = {
id: 2,
name: 'Jane Doe',
age: 34,
city: 'Chicago'
};
// running the function with `objectB` and `expectedKeys`
// should return `false`
const objectB = {
id: 3,
age: 33,
city: 'Peoria'
};
const expectedKeys = [
'id', 'name', 'age', 'city'
];
function validateKeys(object, expectedKeys) {
// your code here
if (Object.keys(object).length === expectedKeys.length) {
return true;
} else if (Object.keys(object).length !== expectedKeys.length) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment