Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9199337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:30:48+00:00 2026-06-17T22:30:48+00:00

I have a object that contains multiple (10) objects. 1 object looks like this:

  • 0

I have a object that contains multiple (10) objects.

1 object looks like this:

bracket: null
bracket_id: null
game_site: null
game_site_id: null
id: 88462
next_game_for_loser: null
next_game_for_loser_id: null
next_game_for_winner: null
next_game_for_winner_id: null
next_team_for_loser: 1
next_team_for_winner: 1
number_of_sets: 5
pool: Object
pool_id: 18739
pool_round: Object
pool_round_id: 21984
season: Object
season_id: 20167
start_time: "2013-03-04T13:00:00+01:00"
swiss_round: null
swiss_round_id: null
team_1: Object
team_1_id: 21202
team_1_score: 3
team_2: Object
team_2_id: 21206
team_2_score: 1
time_created: "2012-12-09T12:46:33.626319+00:00"
time_last_updated: "2012-12-09T12:46:33.626361+00:00"
timezone: "Europe/Amsterdam"
tournament: Object
tournament_id: 18519
winner: Object
winner_id: 21202

I want to filter the objects on matchups (team id’s)

I filter like so:

var game = games.objects.filter(function (gameInfo) { 

            if (gameInfo.team_1_id == team1ID && gameInfo.team_2_id == team2ID) {
                return (gameInfo.team_1_id == team1ID && gameInfo.team_2_id == team2ID) && (inverted = 1);
            } 

            else if (gameInfo.team_1_id == team2ID && gameInfo.team_2_id  == team1ID) {
                return (gameInfo.team_1_id == team2ID && gameInfo.team_2_id  == team1ID) && (inverted = 0);
            }
        });

I got 2 variables to set the team id:

var team1ID = 21206;
var team2ID = 21202;

I want the filter function to return the specific object where it matches the teamID1 and teamID2. This works good if gameInfo.team_1_id == team1ID && gameInfo.team_2_id == team2ID
But when i invert it like so: else if (gameInfo.team_1_id == team2ID && gameInfo.team_2_id == team1ID) Then the object game is always empty…Why is that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:30:49+00:00Added an answer on June 17, 2026 at 10:30 pm
    (inverted = 0)
    

    Here you are assigning, not comparing. The resulting value (0) will always be falsy, and the filter function will return an empty game array.

    Also, you should check for the inverted flag first, and not duplicate the other comparisons unnecessary:

    var game = games.objects.filter(function (gameInfo) { 
        return inverted == 1
          ? gameInfo.team_1_id == team1ID && gameInfo.team_2_id == team2ID
          : gameInfo.team_1_id == team2ID && gameInfo.team_2_id == team1ID;
    });
    

    If you want to set it, it should look like this:

    var inverted;
    var game = games.objects.filter(function (gameInfo) { 
        if (gameInfo.team_1_id == team1ID && gameInfo.team_2_id == team2ID) {
            inverted = 0;
            return true;
        } else if (gameInfo.team_1_id == team2ID && gameInfo.team_2_id == team1ID) {
            inverted = 1;
            return true;
        } // else
            return false;
    });
    
    // Shorter, using the comma operator:
    
    var game = games.objects.filter(function (gameInfo) { 
        return (gameInfo.team_1_id == team1ID && gameInfo.team_2_id == team2ID && (inverted = 1, true)
            || (gameInfo.team_1_id == team2ID && gameInfo.team_2_id == team1ID && (inverted = 0, true);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string that contains multiple parameters delimited by #, like this :
I have an object that contains a array. On initialization of this object, the
I have an array that contains multiple objects with many properties. I want to
I have an SVG map that contains multiple PATH objects. There's an overlaying image
I have a class that I want to contain multiple objects of something I
I have a object that contains data from a DB. The object has a
I have an object that contains about half a dozen properties. I expect to
For example lets say I have a JSON object that contains states and cities.
I have a Grails command object that contains an emailAddresses field, e.g. public class
I have a C# string object that contains the code of a generic method,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.