917. 浠呬粎鍙嶈浆瀛楁瘝
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了917. 浠呬粎鍙嶈浆瀛楁瘝相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/line' title='line'>line
isp bsp span filter join only imp class 1/**
2 * @param {string} S
3 * @return {string}
4 */
5var reverseOnlyLetters = function(S) {
6 let reverseArr = [...S].filter(item => /[A-Za-z]/.test(item)).reverse();
7 return [...S]
8 .map(item => /[A-Za-z]/.test(item) ? reverseArr.shift() : item)
9 .join(鈥樷€?/span>);
10};
11
12ensureEqual(reverseOnlyLetters("ab-cd"), "dc-ba", 鈥榯est1鈥?/span>);
13ensureEqual(reverseOnlyLetters("a-bC-dEf-ghIj"), "j-Ih-gfE-dCba", 鈥榯est2鈥?/span>);
14ensureEqual(reverseOnlyLetters("Test1ng-Leet=code-Q!"), "Qedo1ct-eeLg=ntse-T!", 鈥榯est3鈥?/span>);
以上是关于917. 浠呬粎鍙嶈浆瀛楁瘝的主要内容,如果未能解决你的问题,请参考以下文章