Updated card counting helper function to use array map method