-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
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
[js] 第133天 写一个方法,将字符串中的单词倒转后输出,如:my love -> ym evol #1118
Comments
|
let b = "my love"
function fn(b){
return b.split(" ").map(val => val.split("").reverse().join("")).join(" ")
}
console.log(fn(b)) //ym evol |
let wordReversal = str =>
str
.split(' ')
.map(e => e.split('').reverse().join(''))
.join(' ') |
|
const reverseStr = (str) =>
str
? str
.split("")
.reverse()
.join("")
: str;
console.log(reverseStr('my love'));
console.log(reverseStr('abc cba abc')); |
我最先想到的也是用Array.reverse() |
function reverseStr (str) {
return str.split('').reverse().join('')
} |
|
|
|
能不能不用reverse🙃 function reverseString (string) {
if (typeof string !== 'string') {
return 'hello world!'
}
string = string.split('')
let length = string.length
for (let i = 0, len = Math.floor(length / 2); i < len; i++) {
let t = string[i]
string[i] = string[length - i - 1]
string[length - i - 1] = t
}
return string.join('')
} |
你似乎没看清楚题目意思 |
` console.log(reverseString("my love")); |
function reverseStr(str){
return str.split(' ').map(item => item.split('').reverse().join('')).join(' ')
} |
str1.split(' ').map(item => item.split('').reverse().join('')).join(' ') |
第133天 写一个方法,将字符串中的单词倒转后输出,如:
my love
->ym evol
The text was updated successfully, but these errors were encountered: