I want to iterate through an array of functions, passing each of them some parameters.
let board;
let hand;
const HandCheckers = [
CheckForRoyalFlush(board, hand),
CheckForStraightFlush(board, hand),
CheckForQuads(board, hand),
CheckForFullHouse(board, hand),
CheckForFlush(board, hand),
CheckForTrips(board, hand),
CheckForPairs(board, hand),
CheckForHighCard(board, hand),
];
for (let x = 0; x < HandCheckers.length; x ++) {
HandCheckers[x](board, hand);
}
However, this code fails, giving me the following problem: ReferenceError: board is not defined
How can i call functions like this from an array with parameters?
Cheers!
HandCheckersarray. The error tells exactly that - you're referring a variable that is not defined.boardandhandwere not defined in either case. What exactly are you trying to achieve?const HandCheckers = [ CheckForRoyalFlush(board, hand), CheckForStraightFlush(board, hand), ... ];try just giving a reference, then you can call it in your for statement by passing in board and handconst HandCheckers = [ CheckForRoyalFlush, CheckForStraightFlush, ... ];