Quotes help make search much faster. Example: "Practice Makes Perfect"

Thursday, December 15, 2016

Codefights lineUp(commands);


//sample solution
function lineUp(commands) {
var temp=commands.split("");
    temp.reverse();
    var sum=0;
    var count=0;
    for(i=0;i<commands.length;i++){
    var letter = temp.pop();
    //document.writeln(letter,"<br/>");
        if(letter=='L'){
        sum=sum-1;
        } else if(letter=='R'){
        sum=sum+1;
        } else if(letter=='A'){
        sum=sum+2;
        }
        //document.writeln(sum,"<br/>");
        if(sum%2==0){
        count++;
        }
    }
    return count;
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts