0
点赞
收藏
分享

微信扫一扫

JavaScript 实现找出字符串中第一个没重复的字符

alanwhy 2022-03-22 阅读 60
javascript

JavaScript 实现找出字符串中第一个没重复的字符

function getOnceChar(str) {
	const map = {};

	for (let i = 0; i < str.length; i++) {
		if (!map[str[i]] && str.indexOf(str[i], i + 1) === -1) {
			return str[i];
		}

		map[str[i]] = true;
	}
}
getOnceChar('aaaabbbcddcerr'); // e
举报

相关推荐

0 条评论