Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@westc
Last active May 5, 2019 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westc/3198418a6b09258feaf40994bb1164c1 to your computer and use it in GitHub Desktop.
Save westc/3198418a6b09258feaf40994bb1164c1 to your computer and use it in GitHub Desktop.
Gets the number of the column from the letter reference.
/**
* Gets the number of the column from the letter reference
* (eg. A -> 1, B -> 2, G -> 7, AC -> 29, etc.).
* @param {string} letters
* The letters referring to column which will be converted to a number.
* @return {number}
* The column number represented by the given letters.
*/
function getColNum(letters) {
var num = 0;
letters.replace(/[A-Z]/gi, function(m, i, s) {
num += (parseInt(m, 36) - 9) * Math.pow(26, s.length - i - 1);
});
return num;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment