挑战:
将字符串转换为 spinal case。Spinal case 是 all-lowercase-words-joined-by-dashes 这种形式的,也就是以连字符连接所有小写单词。
例如:
spinalCase("This Is Spinal Tap") 应该返回 "this-is-spinal-tap"。
spinalCase("thisIsSpinalTap") 应该返回 "this-is-spinal-tap"。
spinalCase("The_Andy_Griffith_Show") 应该返回 "the-andy-griffith-show"。
spinalCase("Teletubbies say Eh-oh") 应该返回 "teletubbies-say-eh-oh"。
答案:
方法 | 描述 |
---|---|
replace() | 在字符串中查找匹配的子串, 并替换与正则表达式匹配的子串。 |
split() | 把字符串分割为字符串数组。 |