Excelの列はA, B, C...と続き、Z, AA, AB, AC..., AZ, BA, BB, BC..., ZZ, AAA, AABと表現されます。
この文字列を返す以下の仕様の関数 indexToExcelColumnKey() を生成せよ。
const ALPHABET_NUM = 26 // この関数を実装する function indexToExcelColumnKey(num) { } // コマンドライン引数の数だけ表示する for (let i = 0; i < Number(process.argv[2]); i++) { console.log(indexToExcelColumnKey(i)) }
#
node excel.js 3
A B C
#
node excel.js 30
. . . W X Y Z AA AB AC AD
#
node main.js 704
出力結果
. . . ZX ZY ZZ AAA AAB
#
node excel.js 18280
. . . ZZX ZZY ZZZ AAAA AAAB
475256, 12356632
ヒント
↓この関数を使います
String.fromCharCode String.charCodeAt
解答例
const ALPHABET_NUM = 26 function indexToExcelColumnKey(num) { let ret = "" if (num >= ALPHABET_NUM) { ret = indexToExcelColumnKey(num / ALPHABET_NUM - 1) } ret += String.fromCharCode("A".charCodeAt(0) + num % ALPHABET_NUM) return ret } for (let i = 0; i < Number(process.argv[2]); i++) { console.log(indexToExcelColumnKey(Number(i))) }