Discuss / JavaScript / 看我用 str转ASCII码进行比较完成练习

看我用 str转ASCII码进行比较完成练习

Topic source

Kiah

#1 Created at ... [Delete] [Delete and Lock User]

return arr.map(function (str, index, arr) {

    let newStr = ""

    let i = 0

    while(i<str.length){

        if (i !== 0 && (str[i] <= 'Z')) {

            newStr += String.fromCharCode(str[i].charCodeAt() + 32)

        }else if(i === 0 && (str[i] >= 'Z')) {

            newStr += String.fromCharCode(str[i].charCodeAt() - 32)

        }else{

            newStr += str[i]

        }

            i++;

    }

   return newStr;

})


  • 1

Reply