Elegant function to "increase" a JavaScript string - for example, turning "aac" into "aad" I'm writing a function to increase a string so, for example, "aac" becomes "aad" and "aaz" becomes "aba". The result is horribly inelegant, I can't get it simple enough and I feel I'm missing something. How to improve that code?

function inc_str(str){
    var str = str.split("").map(function(a){ return a.charCodeAt(0); });
    var n = 1;
    while (n&lt;str.length){
        str[str.length-n]++;
        if (str[str.length-n] &gt; "z".charCodeAt(0))
            str[str.length-n] = "a".charCodeAt(0),
            ++n;
        else
            break;
    };
    return str.map(function(a){ return String.fromCharCode(a); }).join("");
};


Extra points for a brief functional style solution! (Even if it needs to implement other functional functions such as zip or whatever.)
A recursive approach is much more elegant in this case:

function inc_str(str) {
  var last = str[str.length - 1],
    head = str.substr(0, str.length - 1);
  if (last === "z") {
    return inc_str(head) + "a";
  } else {
    return head + String.fromCharCode(last.charCodeAt(0) + 1);
  }
}


Making it wrap around for inc_str('z') is left as an exercise for the reader (hint: last becomes undefined).