function test(str){
let _length = 0;
let result = [];
let str_list = str.split('');
let _result = new Set(str_list);
for (let w of _result) {
let number = str_list.filter(element => element === w).length;
if (number > _length) {
result = [
{
_length: number,
word: w
}
];
_length = number;
} else if (number === _length) {
result.push({
_length: number,
word: w
});
}
}
return result
}
test("a eh sjdh s d");//[{_length: 2, word: "h"},{_length: 2, word: "s"},{_length: 2, word: "d"}]
网友评论