Я привязываю, чтобы отфильтровать шаблон для игрового автомата, в этом случае я хочу, чтобы следующие индексы были выбраны, если они имеют одинаковое значение.
Если индексы 0, 2 и 6 имеют одинаковое значение, если они должны выводиться. Я думал о чем-то вроде вызова функции, может быть, как это
if (win_filter([0, 2, 6] == "slot-2") {
console.log("You won");
}
Мой код приведен ниже.
var final_score = new Array();
$(".shoot").click(function() {
//var numbers_array = ["slot-1", "slot-1", "slot-1", "slot-1", "slot-1", "slot-2", "slot-2", "slot-2", "slot-2", "slot-3", "slot-3", "slot-3", "slot-4", "slot-4", "slot-5"];
var numbers_array = ["slot-1", "slot-2", "slot-3", "slot-4", "slot-5"];
var target = $("div.window table");
target.find("tr td > div").each(function() {
$(this).fadeOut(function() {
$(this).removeAttr('class');
$(this).addClass(numbers_array[Math.floor(Math.random() * numbers_array.length)]);
$(this).fadeIn();
final_score.push($(this).attr("class"));
});
});
function filterResults(arr) {
return final_score.filter(function(el) {
return arr.some(function(e) {
return el.timeframe == e;
});
});
}
var result = filterResults(['0','2','6']);
console.log(result);
$.each(numbers_array, function(index, value) {
if (result == value) {
$(".notice").html("You have won.").addClass("success").show();
console.log("You won!");
}
});
console.log(final_score);
});
Edit
Если это было неясно, я имел в виду индексы в массиве, в случае, если я выбрал индексы 0, 2 и 6 из этого сгенерированного массива, это значение будет (даже если они не совпадают).
0 => "slot-2", 2 => "slot-5", 6 => "slot-1"
Цель состоит в том, чтобы проверить, имеет ли выбранные индексы одинаковые значения. И количество индексов не должно быть жестко запрограммированным, это может быть что угодно: от трех индексов до 5 запросов индекса.
Array[0]
0 : "slot-2"
1 : "slot-3"
2 : "slot-5"
3 : "slot-5"
4 : "slot-4"
5 : "slot-3"
6 : "slot-1"
7 : "slot-4"
8 : "slot-1"
9 : "slot-2"
10 : "slot-2"
11 : "slot-4"
12 : "slot-5"
13 : "slot-1"
14 : "slot-4"