Skip to content

Instantly share code, notes, and snippets.

@wkronemeijer
Created November 14, 2015 18:28
Show Gist options
  • Save wkronemeijer/f95e1769e172a1795d7e to your computer and use it in GitHub Desktop.
Save wkronemeijer/f95e1769e172a1795d7e to your computer and use it in GitHub Desktop.
Turning a column name into a number for indexing in the range [1, →)
function parseHeader(letters: string): number {
function letterValue(letter: string): number {
return parseInt(letter, 36) - 9
}
let result = 0
let factor = 1
if (letters.length === 1) {
result = letterValue(letters[0])
} else {
for (let i = letters.length - 1; i >= 0; i -= 1) {
result += factor * letterValue(letters[i])
factor *= 26
}
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment