One of the cleaner ways to accomplish this is with a filter, keeping in mind that filterPasscodes will iterate over the passcodes array and the filterFunction must then iterate over the individual arrays that make up the passcodes array:
var passcodes = [
[1, 4, 4, 1],
[1, 2, 3, 1],
[2, 6, 0, 8],
[5, 5, 5, 5],
[4, 3, 4, 3]
];
// iterate over each array in passcodes, sending each to the filterFunction
// and returning only those arrays that evaluate to true in the filterFunction
function filterPasscodes(filterFunction) {
return passcodes.filter(filterFunction);
}
If you only wanted to find one specific array, use the find method:
function filterPasscodes(filterFunction) {
return passcodes.find(filterFunction);
}
An example filter function for only the passcodes with even numbers:
// given an array, iterate over each element in that array
// and return only those arrays in which each element is even
function allEven(arr) {
return arr.every(function(element) {
return element === 0 || element % 2 === 0);
});
}
console.log(passcode[1])help?