📌  相关文章
📜  圆形打印机hackerrank解决方案——Go编程语言代码示例

📅  最后修改于: 2022-03-11 14:44:59.072000             🧑  作者: Mango

代码示例2
function getTimes(s) {
    let vowels = []
    const strings = Array.from(s)

    for (let i = 1; i <= 26; i++) {
        let values = i - 1
        let keys = 64 + i

        if (values <= 25) {
            vowels.push(String.fromCharCode(keys))
        }
    }

    const str1 = vowels.indexOf('A')
    const str2 = vowels.indexOf(s[0])
    let numb = Math.min(Math.abs(str1 - str2), 26 - Math.abs(str1 - str2))

    for (let i = 1; i < strings.length; i++) {
        const str1 = vowels.findIndex((val) => val == [strings[i]])
        const str2 = vowels.findIndex((val) => val == [strings[i - 1]])
        let result = Math.abs(str1 - str2)

        if (result > 13) {
            numb += 26 - result
        } else {
            numb += result
        }
    }

    return numb
}

;(function () {
    const record = getTimes('BZA')
    console.log(record)
})()