code: function(hexNum) {
              if(typeof hexNum !== "number") {
                  hexNum = parseInt(hexNum, 16);
              }
              if(isNaN(hexNum) || hexNum < 0x000000 || hexNum > 0xffffff) {
                  return undefined;
              }
              var r = (hexNum & 0xff0000) >> 16,
                  g = (hexNum & 0x00ff00) >> 8,
                  b = hexNum & 0x0000ff;
  
              return Math.round(0.2126 * r + 0.7152 * g + 0.0722 * b);
          }
docs: calculate the luminance of a color based on its hex value returns undefined if the input is cannot be parsed to a valid number or if the number is out of range equation for luminance found at http://en.wikipedia.org/wiki/Luma_(video)