挑战涉及简单地在另一个字符串中切换一个字符串。
说明
如果切换字符串是主字符串的子字符串,则从主字符串中删除切换字符串的所有实例; 否则,将切换字符串附加在main string的末尾。
规则
- 所有字符串均由可打印的ASCII字符组成
- 该函数应带有两个参数:主字符串和切换字符串。
- 在主串可以是空的。
- 该拨动弦不能为空。
- 结果应该是一个字符串,可以为空。
- 最短的答案将获胜。
例子
function toggle(main_string, toggle_string){ ... }
toggle('this string has 6 words ', 'now')
=> 'this string has 6 words now'
toggle('this string has 5 words now', ' now')
=> 'this string has 5 words'
测试案例
'','a' => 'a'
'a','a' => ''
'b','a' => 'ba'
'ab','a' => 'b'
'aba','a' => 'b'
'ababa', 'aba' => 'ba'