Alpha Grouping

2011-12-12
2013-05-30
  • John Glasson
    John Glasson
    2011-12-12

    I've tried the Alpha Grouping solution given on the Scripting web page.  I find it more intuitive that the number given as the 'boxtype' should indicate the number of letters in each group (rather than 'choice of a (predefined) set of abcboxes').

    This approach also  enables a much simpler javascript solution.  See below.  For the sake of simplicity I've dropped the 'divchar ' option.

    function AlphaGroup(toGroup, inGroup)
    {
    var Group = ''
    var asciiA = 65; var maxchar = 26;
    var intchar = toGroup.toUpperCase().charCodeAt(0) - asciiA;
    if (intchar < 0) {return '0-9'};

    var firstLetter = Math.floor(intchar / inGroup) * inGroup;
    for (var i=0; i<inGroup; i++) {
    if (firstLetter + i < maxchar) Group = Group+ String.fromCharCode(firstLetter + asciiA +i );
    }
    return Group;
    }