We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9a335b1 commit 7b5c607Copy full SHA for 7b5c607
171-excel-sheet-column-number.js
@@ -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
0 commit comments