We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定任意字符串,进行字符串大小写取反
还是说说第一时间想到的吧,正则匹配每一个字符进行比较后取反:
const transformCase = (str) => str.replace(/[a-zA-Z]/g, item => { return item === item.toUpperCase() ? item.toLowerCase() : item.toUpperCase() })
小写字符的ascii码大于大写字符的ascii,并且大写Z的ascii为90,那么可以换种思路:
const transformCase = (str) => { const array = str.split('').map(item => item.codePointAt(0) <= 90 ? item.toLowerCase() : item.toUpperCase()) return array.join('') }
正则match?
const transformCase = (str) => { return str.replace(/[a-zA-Z]/g, match => /[a-z]/.test(match) ? match.toUpperCase() : match.toLowerCase()) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
给定任意字符串,进行字符串大小写取反
还是说说第一时间想到的吧,正则匹配每一个字符进行比较后取反:
小写字符的ascii码大于大写字符的ascii,并且大写Z的ascii为90,那么可以换种思路:
正则match?
The text was updated successfully, but these errors were encountered: