Tuesday, February 23, 2016

#javascript generating ASCII char code arrays for various ranges

var numArr = []
var specialArr = []
var charArr = []


putRange = function(startChar, endChar)
{
    var arr = []
    for(var i = startChar.charCodeAt(0); i < endChar.charCodeAt(0); i++)
    {
        arr.push(i)
    }
    return arr}


numArr = putRange('0', '9')
specialArr = putRange('!', '/')
charArr = putRange('a', 'z').concat(putRange('A', 'Z'))


This generates the following

charArr [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89]

specialArr [33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46]

numArr [48, 49, 50, 51, 52, 53, 54, 55, 56]

No comments:

Post a Comment

There was an error in this gadget