对单词中的字母种类和个数进行摘要的方法

部分场景中需要对 某个单词 进行摘要,只需要 单词中 **包含的字母的种类和个数相同** 就是相同,就需要实现方法 让 `function('tea') = function('aet')`

#type / resource #status / evergreen

[!info] related notes 字母异味词分组

对单词中的字母种类和个数进行摘要的方法

部分场景中需要对 某个单词 进行摘要,只需要 单词中 包含的字母的种类和个数相同 就是相同,就需要实现方法 让 function('tea') = function('aet')

构造 hash 字符串

function digestWithConstructedHash(word: String) {
	let counts = new Array(26).fill(0)

	for (let i = 0; i < word.length; i++) {
		counts[word.charCodeAt(i) - 97]++;
	}
	const key = counts.join('#')
	return key;
}

对字母进行排序

function digestBySort(word: String) {
	
	const key = [...word].sort().join('');
	return key;
}
创建于 2026/3/3 更新于 2026/5/27