我正在尝试制作一个饮料网络应用程序,用户在其中输入成分,然后返回饮料或鸡尾酒的名称。
我的饮料阵列如下所示:
// Drinks
var drinks = new Array(
[0,['Whisky on the Rocks'],['whisky','ice']],
[1,['Vodka on the Rocks'],['vodka','ice']]
);
我有这个票价,但它只返回第一个元素:
function compare(myDrink) {
var difference = [];
difference[0] = [];
difference[0][0] = [];
var dCount = drinks.length;
for (x = 0;x < dCount; x++) {
jQuery.grep(drinks[x][2], function(el) {
if (jQuery.inArray(el, myDrink) == -1){
difference[x][0].push(el);
difference[x][1] = difference[x][0].length;
}
});
var theDrink = difference[x][0].join(',');
if (theDrink == ''){
return drinks[x][1];
} else {
var diff = 'The Difference is: ' + difference[x][1] + ' Missing: ' + theDrink;
return diff;
}
}
}
我究竟做错了什么?有没有更好的方法呢?
提前致谢,
罗伯特