Tests:
  • A

    AخA
     
    var firstMissingPositive = function(nums) {
        nums = nums.sort(function(val1, val2) {
           return val1>val2?1:val1<val2?-1:0; 
        });
        if(nums.length===0||nums[nums.length-1]<=0){ return 1; } // A, B
        for(var i=0,k=1; i<nums.length; ++i){ // C
            if(nums[i]>k){ return k; }
            k = nums[i]<k?k:k+1;
        }
        return nums[nums.length-1]+1; // D
    };
  • V

     
    var firstMissingPositive = function (nums) {
        let s = 1;
        let i = 0;
        let w = false;
            do {
                w = false;
                for (i = 0; i < nums.length; i++) {
                    if (s == nums[i]) {
                        s++;
                        w = true;
                    }
                }
            } while (w == true)
        return s
        };
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    A
    V

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
Chrome 83 on Windows
View result in a separate tab
Test name Executions per second
A 1098003712.0 Ops/sec
V 1095118080.0 Ops/sec