lolilol

Benchmark created on


Preparation HTML

var mySpiral =function(a,b,c,d){
var solution = [];
var lengthOfSegment = 0; 
var sens = 1;
var add=-1;
        var spiralGrid=function( Width,Height,Row,Col,currentPositionOnSegment){  
                debugger
                var index = Height*(Row-1)+Col; 
                if(0<index&&index<=Width*Height && Row >0 && Col >0) solution.push(index);

        if (solution.length===Width*Height) return;
        if(lengthOfSegment===currentPositionOnSegment && sens===-1){            
                sens=1; 
                currentPositionOnSegment=0;
                Col+=add;
                        add*=-1;
                        ++lengthOfSegment;
        } else if (lengthOfSegment!==currentPositionOnSegment && sens===-1){
                ++currentPositionOnSegment;
                Col+=add;
        }else if(lengthOfSegment===currentPositionOnSegment && sens===1){
                sens=-1;                        
                currentPositionOnSegment=0;
                Row+=add;
        }else if(lengthOfSegment!==currentPositionOnSegment && sens===1){
                ++currentPositionOnSegment;
                Row+=add;
        }     
    
        spiralGrid(Width,Height,Row,Col,currentPositionOnSegment);
    
        }
spiralGrid(a,b,c,d,0);
return solution;
}

var first = mySpiral(5,5,3,3);
var second = mySpiral(2,4,1,2);
console.log(first,second);

Test runner

Ready to run.

Testing in
TestOps/sec
lolilol1
var mySpiral =function(a,b,c,d){
var solution = [];
var lengthOfSegment = 0; 
var sens = 1;
var add=-1;
        var spiralGrid=function( Width,Height,Row,Col,currentPositionOnSegment){  
                debugger
                var index = Height*(Row-1)+Col; 
                if(0<index&&index<=Width*Height && Row >0 && Col >0) solution.push(index);

        if (solution.length===Width*Height) return;
        if(lengthOfSegment===currentPositionOnSegment && sens===-1){            
                sens=1; 
                currentPositionOnSegment=0;
                Col+=add;
                        add*=-1;
                        ++lengthOfSegment;
        } else if (lengthOfSegment!==currentPositionOnSegment && sens===-1){
                ++currentPositionOnSegment;
                Col+=add;
        }else if(lengthOfSegment===currentPositionOnSegment && sens===1){
                sens=-1;                        
                currentPositionOnSegment=0;
                Row+=add;
        }else if(lengthOfSegment!==currentPositionOnSegment && sens===1){
                ++currentPositionOnSegment;
                Row+=add;
        }     
    
        spiralGrid(Width,Height,Row,Col,currentPositionOnSegment);
    
        }
spiralGrid(a,b,c,d,0);
return solution;
}

var first = mySpiral(5000,5000,3,3);
var second = mySpiral(2,4,1,2);
console.log(first,second);
ready
lol5
var mySpiral =function(a,b,c,d){
var solution = [];
var lengthOfSegment = 0; 
var sens = 1;
var add=-1;
        var spiralGrid=function( Width,Height,Row,Col,currentPositionOnSegment){  
                debugger
                var index = Height*(Row-1)+Col; 
                if(0<index&&index<=Width*Height && Row >0 && Col >0) solution.push(index);

        if (solution.length===Width*Height) return;
        if(lengthOfSegment===currentPositionOnSegment && sens===-1){            
                sens=1; 
                currentPositionOnSegment=0;
                Col+=add;
                        add*=-1;
                        ++lengthOfSegment;
        } else if (lengthOfSegment!==currentPositionOnSegment && sens===-1){
                ++currentPositionOnSegment;
                Col+=add;
        }else if(lengthOfSegment===currentPositionOnSegment && sens===1){
                sens=-1;                        
                currentPositionOnSegment=0;
                Row+=add;
        }else if(lengthOfSegment!==currentPositionOnSegment && sens===1){
                ++currentPositionOnSegment;
                Row+=add;
        }     
    
        spiralGrid(Width,Height,Row,Col,currentPositionOnSegment);
    
        }
spiralGrid(a,b,c,d,0);
return solution;
}

var first = mySpiral(5000,5000,3,3);
var second = mySpiral(2,4,1,2);
console.log(first,second);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.