Javascript String reverseString(s)

Description

Javascript String reverseString(s)


// reverse string
var reverseString = function(s) {
    var left = 0,
        right = s.length - 1;// w  ww  .  j  av a2s.  c  o m
    str = s.split('');
    
    while (left <= right) {
        var temp = str[left];
        str[left] = str[right];
        str[right] = temp;
        
        left++;
        right--;
    }
    
    return str.join('');
};



PreviousNext

Related