codewars-js练习
2021/3/4
github 地址
【1】<8kyu>【Reversed Words】
Given number n, such that n > 1, find if its 2nd root, 4th root and 8th root are all integers (fractional part is 0), return true if it exists, false if not.
example:
reverseWords("The greatest victory is that which requires no battle")
// should return "battle no requires which that is victory greatest The"
solution
<script type="text/javascript">
function reverseWords(str){
return (str.split(' ')).reverse().join(' ')
}
// 验证
console.log(reverseWords("hello world!"));// "world! hello"
</script>
以上为自己思路供大家参考,可能有更优的思路。
开组会,些许有点偷懒…
本文介绍了一个简单的JavaScript函数实现,该函数用于反转字符串中的单词顺序。通过使用split、reverse和join方法组合实现了这一功能。文章还提供了一个示例用以验证函数的正确性。
225





