Skip to content

Instantly share code, notes, and snippets.

@gusmcnair
Created October 2, 2019 23:01
Show Gist options
  • Save gusmcnair/13a1150ccbf9ab9fa47b010471ce3181 to your computer and use it in GitHub Desktop.
Save gusmcnair/13a1150ccbf9ab9fa47b010471ce3181 to your computer and use it in GitHub Desktop.
Iterating Through Objects problems
Make Students Report
function makeStudentsReport(data) {
let students = [];
for (i = 0; i < data.length; i++){
students.push(`${data[i].name}: ${data[i].grade}`)
} return(students);
}
Enroll in Summer School
function enrollInSummerSchool(students) {
for(i = 0; i < students.length; i++){
students[i].status = "In summer school";
} return students;
}
Find By ID
function findById(items, idNum) {
for(i = 0; i < items.length; i++){
if(idNum === items[i].id){
return items[i]
}}
}
Object Keys
function validateKeys(object, expectedKeys) {
if (Object.keys(object).length !== expectedKeys.length){
return false
}
for(i = 0; i < expectedKeys.length; i++){
if (expectedKeys[i] !== Object.keys(object)[i]){return false}
} return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment