xxxxxxxxxx
<html>
<head>
<meta charset="utf-8">
<title>Tinkering with Javascript</title>
</head>
<body>
<script>
var h = {
name: 'Computer',
cost: '$1,000'
};
var test1 = [];
var test2 = ['name', 'cost'];
var test3 = ['name', 'bio', 'cost'];
var hasElems = function (obj, arr) {
for (i = 0; i < arr.length; i++) {
// commenting this to conceal the answer
}
return true;
}
console.log('returns true for an empty array', hasElems(h, test1));
console.log('returns true if it has all the keys', hasElems(h, test2));
console.log('returns false if one or more of the keys isn’t in the hash', hasElems(h, test3));
</script>
</body>
</html>