DEV Community

Karleb
Karleb

Posted on

3110. Score of a String

https://leetcode.com/problems/score-of-a-string/?envType=daily-question&envId=2024-06-01

/**
 * @param {string} s
 * @return {number}
 */
var scoreOfString = function(s) {
    let res = 0

    for(let i = 0; i < s.length - 1; i++) {
       res += Math.abs(s[i].charCodeAt(0) - s[i + 1].charCodeAt(0))
    }

    return res
};

Enter fullscreen mode Exit fullscreen mode

Top comments (0)