I am working on trying to create a range function in JavaScript that imitates PERL's 'a'..'zz'.which expands to:a->zaa->azba->bz...za->zzAnd so on for every extra character you add to the end of the range( e.g zzz .... ).I have a working implementation, However, I think that there is a more efficient - and perhaps more idiomatic - solution.There are two things I would like answers to address:I would like to reduce the code size - this seems like too many lines for the problem that it solves.I would like improve the performance - the implementation that I have is very slow for any end string > 5 characters long.function charRange( start, end ) {  var current = start;  var range   = [];  range.push( current ); //Put the start directly into the range.  if ( typeof start === typeof end &&     ( typeof start === string )) {    if ( typeof end !== string ) {        console.log( ERROR: start and end must both be Strings! );    }  }  while ( !stringEqual(current.split(), end.split()) ) {    current = next(current);    range.push( current );    // process.exit();  }  return range;  function stringEqual( chars, testChars ) {    var isEqual = 1;    var sum = 0;    var testSum = 0;    var i = 0;    while ( i < testChars.length ) {        // console.log(chars);        // console.log(testChars);        // console.log(i);        if ( isEqual && chars[i] !== testChars[i] ) {            isEqual = 0;        };        if ( chars[i] ) {            sum     += chars[i].charCodeAt(0);        };        testSum += testChars[i].charCodeAt(0);        i++;    }    // console.log( sum +   + testSum );    return isEqual || (sum < testSum ? 0 : 1);  }  function allAreZ( string ) {    var found = 1;    var i     = 0;    while ( i < string.length ) {        if ( string[i] !== z ) {            found = 0;            break;        }        i++;    }    return found;  }  function findIncrementIndex( item ) {    var index = item.indexOf(z);    var i     = 0;    while (index === 0) {        i++;        index = item.substr(i).indexOf(z);    }    index += i;    return index;  }  function next( item ) {    if ( typeof item === number ) {        return item++;    } else if ( typeof item === string ) {        var lastCharCode = item.charCodeAt( item.length -1 );        item = item.toLowerCase();        if ( lastCharCode === z.charCodeAt( 0 ) ) {            if ( allAreZ(item) ) {                // console.log( Reached the end, adding a letter);                return Array(item.length +2).join(a);                } else {                 var index = findIncrementIndex(item);                var charCode = item.charCodeAt( index -1 );                var newChar = String.fromCharCode( ++charCode );                item = item.replace(/[a-y]z/, newChar + a).replace(/z+$/, a);                // console.log( Reached the end, next set is:  + item);                return item;            }        } else {            var newChar = String.fromCharCode( ++lastCharCode );            // console.log( Next Character is:  + newChar +  Code:  + lastCharCode +  Input:  + item);            return item.replace( /\w$/, newChar );        }    }  }};
Character range generator
javascript;performance