1

Basically, if a candidates id is found in the candidates_ignore array, then they should be added to the rejected list, otherwise they will be added to the included list

All the candidates apart from id 33 are in the list. But for some reason the one with id 33 is being included not rejected

see this screenshot

As you can see in the console, 33 is not in the ignore list so that should be included. But for whatever reason 23 is being included even though he is in the ignore list??

The code:

            if($.inArray(cand.id, candidates_ignore)) {

                $results_rejected.append(output);
            }
            else {

                $results_included.append(output);
            }

The full code:

http://pastebin.com/mDQksz5r

Ben
  • 5,627
  • 9
  • 35
  • 49

1 Answers1

1

From jQuery website:

The $.inArray() method is similar to JavaScript's native .indexOf() method in that it returns -1 when it doesn't find a match. If the first element within the array matches value, $.inArray() returns 0.

Because JavaScript treats 0 as loosely equal to false (i.e. 0 == false, but 0 !== false), to check for the presence of value within array, you need to check if it's not equal to (or greater than) -1.

The comparison between values is strict. The following will return -1 (not found) because a number is being searched in an array of strings:

if($.inArray(cand.id, candidates_ignore)<0) {

    $results_rejected.append(output);
}
else {

    $results_included.append(output);
}

https://api.jquery.com/jQuery.inArray/

Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171