编写一个函数,它接受两个字符串并显示出现在任一字符串中的字符(不带双精度)。
function characteroverlap(array1, array2) { let occurrence = {}; let str = array1.concat(array2); // find the count of each character array.from(str).foreach((char) => { let currentcount = occurrence[char] || 0; occurrence[char] = currentcount + 1; }); // return the keys which is the individual character and join. const result = object.keys(occurrence); return result.join(""); } console.log(characteroverlap("computer", "circuitemtop")); console.log(characteroverlap("frontend", "development")); console.log(characteroverlap("mivrog", "gormiv")); console.log(characteroverlap("praxet", "xetpar")); console.log(characteroverlap("stone", "tones")); console.log(characteroverlap("rescue", "secure"));
> computer > frontedvlpm > mivrog > praxet > stone > rescu
以上就是JavaScript 中字符与字符串重叠的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号