29 - Stop gninnipS My sdroW!
3575 ワード
Q.
Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (like the name of this kata).
Strings passed in will consist of only letters and spaces.
Spaces will be included only when more than one word is present.
Examples:
spinWords("Hey fellow warriors") => "Hey wollef sroirraw"
spinWords("This is a test") => "This is a test"
spinWords("This is another test") => "This is rehtona test"
A) function spinWords(string){
//TODO Have fun :)
let arr = string.split(' ');
let result = [];
for (let key of arr) {
if (key.length >= 5) {
result.push(key.split('').reverse().join(''));
}
else {
result.push(key);
}
}
return result.join(' ');
}
Reference
この問題について(29 - Stop gninnipS My sdroW!), 我々は、より多くの情報をここで見つけました
https://velog.io/@developerjhp/알고리즘-29-Stop-gninnipS-My-sdroW
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
function spinWords(string){
//TODO Have fun :)
let arr = string.split(' ');
let result = [];
for (let key of arr) {
if (key.length >= 5) {
result.push(key.split('').reverse().join(''));
}
else {
result.push(key);
}
}
return result.join(' ');
}
Reference
この問題について(29 - Stop gninnipS My sdroW!), 我々は、より多くの情報をここで見つけました https://velog.io/@developerjhp/알고리즘-29-Stop-gninnipS-My-sdroWテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol