Last active
April 1, 2021 14:25
-
-
Save PhilomathJ/33f0aa7089aab06d8ba272e9d715a090 to your computer and use it in GitHub Desktop.
Revisions
-
Jeremy Fairbanks revised this gist
Apr 1, 2021 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,13 +2,13 @@ * Recursively returns the letter combination corresponding to the column for the given index * This is a more functional programming approach compared to the usual loop-based method * Tested to column index out to one decillion * @param {number} num Index to be converted * @returns {string} Letter combination as column indicator */ const columnIndexToLetter = (num: number): string => { return num <= 26 ? String.fromCharCode((num === 0 ? 26 : num) + 64) : columnIndexToLetter(Math.floor((num - 1) / 26)) + columnIndexToLetter(num % 26); }; // Testing -
Jeremy Fairbanks created this gist
Apr 1, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ /** * Recursively returns the letter combination corresponding to the column for the given index * This is a more functional programming approach compared to the usual loop-based method * Tested to column index out to one decillion * @param {number} num Index to be converted * @returns {string} Letter combination as column indicator */ const columnIndexToLetter = (num: number): string => { return num <= 26 ? String.fromCharCode((num === 0 ? 26 : num) + 64) : columnIndexToLetter(Math.floor((num - 1) / 26)) + columnIndexToLetter(num % 26); }; // Testing const column: number = 28; console.log('column', column); const letter = columnIndexToLetter(column); console.log('letter', letter);