!](https://img-blog.csdnimg.cn/direct/bf9a3d781a8043c997593260c0a8306f.png)
第一部分的字符可以少于…
const str = "5F3Z-2e-9w";
const str1 = "2-5g-3-J";
function solution(num, str) {const arr = str.split("-");const head = arr[0];arr.shift();const tailUpperArr = arr.join("").toUpperCase().split("");const tail = tailUpperArr.map((char, index) => {if ((index + 1) % num === 0 && index + 1 !== tailUpperArr.length) {return char + "-";} else {return char;}}).join("");return `${head}-${tail}`;
}console.log(solution(2, str1));
/* 45F3Z-2e-9w => 5F3Z-2E9W 22-5g-3-J => 2-5G-3J*/