Skip to content

Commit 7b5c607

Browse files
committed
Excel Sheet Column Number
1 parent 9a335b1 commit 7b5c607

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

171-excel-sheet-column-number.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {string} columnTitle
3+
* @return {number}
4+
*/
5+
var titleToNumber = function (columnTitle) {
6+
console.log('-'.repeat(100));
7+
let res = 0;
8+
for (let i = 0; i < columnTitle.length; i++) {
9+
console.log({ i });
10+
const n = columnTitle[i].charCodeAt(0) - 'A'.charCodeAt(0) + 1;
11+
res = res * 26 + n;
12+
console.log({ n });
13+
}
14+
return res;
15+
};
16+
17+
console.log(titleToNumber('A')); //1
18+
console.log(titleToNumber('AB')); //28
19+
console.log(titleToNumber('ZY')); //701
20+
21+
// console.log('A'.charCodeAt(0));
22+
// console.log('Z'.charCodeAt(0));
23+
24+
// console.log('A'.charCodeAt(0));

0 commit comments

Comments
 (0)