DEV Community

duccanhole
duccanhole

Posted on

4

code every day with me

--DAY 23--

Hi, I am going to make #100DaysOfCode Challenge. Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
Now let's solve problem today:
Problem: Excel Sheet Column Title
Detail: here
My solution(javascript):

var titleToNumber = function(str) {
    let colNum = '0ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    str = str.split('');
    let result = 0, n = str.length-1;
    for(let i=0;i<str.length;i++){
        result+=((26**n)*colNum.indexOf(str[i]));
        n--;
    }
    return result;
};
Enter fullscreen mode Exit fullscreen mode

-->If you have better solution or any question, please comment below. I will appreciate.

Top comments (0)

Sentry mobile image

App store rankings love fast apps - mobile vitals can help you get there

Slow startup times, UI hangs, and frozen frames frustrate users—but they’re also fixable. Mobile Vitals help you measure and understand these performance issues so you can optimize your app’s speed and responsiveness. Learn how to use them to reduce friction and improve user experience.

Read full post →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay