Last active
May 5, 2019 02:57
-
-
Save westc/3198418a6b09258feaf40994bb1164c1 to your computer and use it in GitHub Desktop.
Gets the number of the column from the letter reference.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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