Last active
January 18, 2022 12:03
-
-
Save iancover/be4009f9829fce5cf2864c55b5e0417c to your computer and use it in GitHub Desktop.
Thinkful JS Object exercise
This file contains hidden or 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
var obj1 = { | |
key1: 1, | |
key2: 'Value2', | |
key3: 3, | |
key4: 'Value4' | |
} | |
var obj2 = { | |
key1: 1, | |
key2: 'Value2', | |
key3: 'Value3' | |
} | |
var someKeys = [ | |
'id', 'name', 'age', 'city' | |
]; | |
function validateKeys(obj,someKeys) { | |
if (Object.keys(obj).length !== someKeys.length) { | |
return false; | |
} | |
for (var i=0; i<someKeys; i++) { | |
if (Object.keys(obj) !== someKeys[i]); | |
return false; | |
} | |
return true; | |
} | |
console.log(validateKeys(obj1,someKeys)); | |
console.log(validateKeys(obj2,someKeys)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 25: can't figure out how I got the loop to work written with 'i<someKeys' and not 'i<someKeys.length'