Determine which range a character falls into I am categorizing terms depending on what letter the term starts with.  What is the cleanest way to do so?

var parentGroup,
    startsWith = "H"; // Just simplifying and giving a static example here.

switch(startsWith) {
    case "A":
    case "B":
    case "C":
    case "D":
    case "E":
    case "F":
        parentGroup = "A-F";
        break;
    case "G":
    case "H":
    case "I":
    case "J":
    case "K":
    case "L":
    case "M":
        parentGroup = "G-M";
        break;
    case "N":
    case "O":
    case "P":
    case "Q":
    case "R":
        parentGroup = "N-R";
        break;
    case "S":
    case "T":
    case "U":
    case "V":
    case "W":
    case "X":
    case "Y":
    case "Z":
        parentGroup = "S-Z";
        break;
    default:
        parentGroup = "0-9";
}
Those "parent groups" look a lot like regular expressions, specifically character sets.  You could perform regular expression matches for patterns like ^[A-F].



function parentGroup(char) {
    var groups = ['A-F', 'G-M', 'N-R', 'S-Z', '0-9'];
    for (var i = 0; i &lt; groups.length; i++) {
        if (char.match('^[' + groups[i] + ']')) {
            return groups[i];
        }
    }
}

document.getElementById('in').addEventListener('keyup', function(e) {
    document.getElementById('out').textContent = parentGroup(e.target.value);
});
&lt;div&gt;Enter text, starting with a digit or uppercase letter: &lt;input id="in" type="text" size="10"&gt;&lt;/div&gt;
&lt;div&gt;Parent group: &lt;span id="out"&gt;&lt;/span&gt;&lt;/div&gt;