Last active
October 15, 2025 19:48
-
-
Save omarluq/735a979d9ff4e2be2bdbb98a723b7f63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function colNameToNum(col) { | |
| let result = 0; | |
| let colName = col.toUpperCase(); | |
| for (let i = 0; i < colName.length; i++) { | |
| // A=1, B=2, ... Z=26 | |
| const charValue = colName.charCodeAt(i) - "A".charCodeAt(0) + 1; | |
| // Base-26 conversion | |
| result = result * 26 + charValue; | |
| } | |
| // Convert to 0-indexed | |
| return result - 1; | |
| } | |
| console.log(colNameToNum("AA")); // 26 | |
| console.log(colNameToNum("a")); // 0 | |
| console.log(colNameToNum("B")); // 1 | |
| console.log(colNameToNum("z")); // 25 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment