<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
var ex = [],
nw = [],
components = {
water: {
value: 500
},
tea: {
value: 250
},
sugar: {
value: 15
}
},
recipes = {
black: {
water: 600,
tea: 270,
sugar: 30
},
gray: {
water: 200,
tea: 350,
sugar: 5
},
green: {
water: 350,
tea: 50,
sugar:20
}
}
function check() {
for (var key in recipes) {
for (var i in recipes[key]) {
if (recipes[key][i] > components[i]) ex.push(i);
}
}
}
check();
console.log(ex);
function finish(arr) {
var obj = {};
for (var i = 0; i < arr.length; i++) {
var str = arr[i];
obj[str] = true;
}
return Object.keys(obj);
}
nw = finish(ex);
console.log(nw);
console.log(typeof(nw));
</script>
</body>
</html>