Created
October 13, 2017 03:15
-
-
Save elliotkim916/c92ce5439335b6b0a9a97b8aec524073 to your computer and use it in GitHub Desktop.
Object Drills 2
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
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; | |
} |
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
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]; | |
} | |
} | |
} | |
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) { | |
// your code here | |
var array = []; | |
for (let i = 0; i < data.length; i++) { | |
array.push(data[i].name + ': ' + data[i].grade); | |
} | |
return array; | |
} | |
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
// 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