在 JavaScript 中包含唯一字符的筛选字符串
问题
我们需要编写一个JavaScript函数来接受一个字符串str。我们的函数应该构造一个只包含输入字符串中唯一字符的新字符串,并删除出现的所有重复字符。
示例
以下是代码-
const str = 'hey there i am using javascript';
const removeAllDuplicates = (str = '') => {
let res = '';
for(let i = 0; i < str.length; i++){
const el = str[i];
if(str.indexOf(el) === str.lastIndexOf(el)){
res += el;
continue;
};
};
return res;
};
console.log(removeAllDuplicates(str));输出结果
以下是控制台输出-
Ymungjvcp
热门推荐
10 国庆简短幽默祝福语
11 新年给妹妹祝福语简短
12 给侄子祝福语简短精辟
13 老公开业祝福语简短
14 周末思念祝福语大全简短
15 女朋友考试祝福语简短
16 写给男生简短的祝福语
17 捐款人留言祝福语简短
18 祝妹妹毕业祝福语简短