JavaScript 函数:反转五个字母以上单词
function reverseWords(str) { let words = str.split(' '); for(let i = 0; i < words.length; i++) { if(words[i].length >= 5) { words[i] = words[i].split('').reverse().join(''); } } return words.join(' '); }
// 示例 reverseWords('Hello world'); // 'Hello dlrow' reverseWords('This is a test'); // 'This is a tset' reverseWords('Welcome to the jungle'); // 'emocleW to the elgnuj'
原文地址: https://www.cveoy.top/t/topic/mBTV 著作权归作者所有。请勿转载和采集!