Created
October 2, 2019 23:01
-
-
Save gusmcnair/13a1150ccbf9ab9fa47b010471ce3181 to your computer and use it in GitHub Desktop.
Iterating Through Objects problems
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
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