JavaScript ClouldCode not returning right results (randomnumber range limited)

My Parse Javascript cloudcode is not working correctly. Basically all my objects have a corresponding "index/menindex & womenindex" number.

If both genders are selected- all items show up (as they should).

If just male or female is selected- it only shows items up to 122309 (womenindex) or 80811 (menindex). I've tried for weeks but cannot figure this one out.

Parse.Cloud.define("standardQuery", function(request, response)  {

var maxIndex = 124940;
var maxWomenIndex = 135354;
var maxMenIndex = 105357;

var arrayOfRandomNumbers = new Array();

var query = new Parse.Query("garmentsAPI");

    if (request.params.gender === "Female") {

        //arrayOfRandoms draws on womenIndex, gender set to female

        for (var k = 0; k < 40; k++) {

            var randomIndex =  Math.floor((Math.random()*maxWomenIndex)+1);

            arrayOfRandomNumbers.push(randomIndex);

                }
        query.containedIn("womenIndex", arrayOfRandomNumbers);
        query.notEqualTo ("viewers", request.params.user);


    }else if (request.params.gender === "Male") {

        for (var k = 0; k < 35; k++) {

            var randomIndex =  Math.floor((Math.random()*maxMenIndex)+1);

            arrayOfRandomNumbers.push(randomIndex);

                }

        query.containedIn("menIndex", arrayOfRandomNumbers);
        query.notEqualTo ("viewers", request.params.user);

        //arrayOfRandoms draws on menIndex, gender set to male

    }else{

        for (var k = 0; k < 35; k++) {

            var randomIndex =  Math.floor((Math.random()*maxIndex)+1);

            arrayOfRandomNumbers.push(randomIndex);

                }

        query.containedIn("index", arrayOfRandomNumbers);
        query.notEqualTo ("viewers", request.params.user);

    };


    if (request.params.gender !== "both") {
    query.equalTo ("gender", request.params.gender);
    };

    query.find({

    success: function(objectsInQuery){

        if (objectsInQuery.length > 15) {

            var arrayOSelectedObjects = new Array();

            for (var j = 0; j < 15; j++) { 

                arrayOSelectedObjects.push(objectsInQuery[j]);

            }

            response.success(arrayOSelectedObjects);

        } else{
                // var existingCount = objectsInQuery.count;
                var missingIndex = 15 - objectsInQuery.length;


                // missingIndex = missingIndex - objectsInQuery.count; 

                var query = new Parse.Query("garmentsAPI");
                if (request.params.gender !== "both") {
                query.equalTo ("gender", request.params.gender);
                };
                query.notEqualTo ("viewers", request.params.user);


                query.limit(missingIndex);
                // query.limit = 9 - objectsInQuery.count;


                query.find({

               success: function(objectsInQuery2){

                if ((objectsInQuery.length + objectsInQuery2.length) === 15) {


                    for (var l = 0; l < missingIndex; l++) { 

                        objectsInQuery.push(objectsInQuery2[l]);

                    }

                    response.success(objectsInQuery);


                } else {



                    //who knows


                    var maxIndex2 = 15000;

                    var arrayOfRandomNumbers2 = new Array();

                    for (var m = 0; m < 15; m++) {

                    var randomIndex =  Math.floor((Math.random()*maxIndex)+1);

                    // var randomIndex =  15;

                    arrayOfRandomNumbers2.push(randomIndex);

                    }


                    var query = new Parse.Query("garmentsAPI");
                    query.containedIn("index", arrayOfRandomNumbers2);
                    if (request.params.gender !== "both") {
                    query.equalTo ("gender", request.params.gender);
                    };
                    // query.notEqualTo ("viewers", request.params.user);


                    query.limit(15);

                    query.find ({


                        success: function (objectsInQuery3){

                            response.success (objectsInQuery3);
                        },

                        error:function() {

                            response.error("there was an error");
                        }


                    }); 


                };



                    },
                error:function() {

            response.error ("didn't work");

                }

            }

                );



        };



            },
        error:function() {

            response.error ("didn't work");

        }

        });

});
Answer:1

I have a problem when setting scope variables with two dots. See below for my controller and my error. .controller('CreateSubject', function ($scope, factory, $cookieStore, $location, $rootScope){ ...

I have a problem when setting scope variables with two dots. See below for my controller and my error. .controller('CreateSubject', function ($scope, factory, $cookieStore, $location, $rootScope){ ...

I am currently using 1.5.3 AngularJS Version & ng-include="'file.html'" is not working <!DOCTYPE html> <html lang="en-US" ng-app="myApp"> <head> <!-- Include ...

I am currently using 1.5.3 AngularJS Version & ng-include="'file.html'" is not working <!DOCTYPE html> <html lang="en-US" ng-app="myApp"> <head> <!-- Include ...

I have following model to collect data. <form class="form-login" name="myform" action="transactionsave.php" method="post"> <div class="modal fade" id="...

I have following model to collect data. <form class="form-login" name="myform" action="transactionsave.php" method="post"> <div class="modal fade" id="...

  1. pass data bootstrap modal
  2. pass parameter bootstrap modal
  3. pass to bootstrap modal
  4. passing id to bootstrap modal
  5. passing values to bootstrap modal
  6. passing object to bootstrap modal
  7. passing data to bootstrap modal angularjs
  8. passing data to bootstrap modal angular 2

I have such string: "{{foo}} is {{bar}}" I would like to extract values from {{}}, how I can achieve this? Expected result is ["foo", "bar"] I tried "{{foo}} is {{bar}}".match(/\{\{(.*?)\}\}/g) ...

I have such string: "{{foo}} is {{bar}}" I would like to extract values from {{}}, how I can achieve this? Expected result is ["foo", "bar"] I tried "{{foo}} is {{bar}}".match(/\{\{(.*?)\}\}/g) ...

  1. javascript simple string hash
  2. javascript simple string encryption
  3. javascript simple string replace
  4. javascript simple string search
  5. javascript simple string compression
  6. javascript simple encode string
  7. javascript simple random string
  8. javascript simple encrypt decrypt string
  9. javascript simple quote in string