softnshare / kata

Code Kata 這個概念是由 The Pragmatic Programmer 的作者之一Dave Thomas提出的, 想要提升自己的coding skill嗎? 歡迎加入這個slack channel, 加入請參考右邊網頁說明
https://softnshare.wordpress.com/slack/kata/
38 stars 4 forks source link

Reversing Words in a String #30

Open freedom5566 opened 6 years ago

freedom5566 commented 6 years ago

https://www.codewars.com/kata/reversing-words-in-a-string

題目:

You need to write a function that reverses the words in a given string. A word can also fit an empty string. If this is not clear enough, here are some examples:

As the input may have trailing spaces, you will also need to ignore unneccesary whitespace.

你需要編寫一個可以反轉字串單字的函式,一個單字也能是一個空字串。如果這不夠清楚,這裡是一些範例。

輸入可能有尾隨空格,你還需要忽略不必要的空格。

reverse("Hello World") === "World Hello"
reverse("Hi There.") === "There. Hi"