Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (37 loc) · 1.46 KB
/
Copy pathindex.js
File metadata and controls
37 lines (37 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"use strict";
exports.__esModule = true;
exports.createSearch = void 0;
var hangul_js_1 = require("hangul-js");
var getChars = function (keyword) {
var chars = {};
(0, hangul_js_1.disassemble)(keyword).map(function (char) {
return (chars[char] = typeof chars[char] !== 'undefined' ? chars[char] + 1 : 1);
});
return chars;
};
var createSearch = function (items) {
var itemCounts = items.map(function (item) { return getChars(item); });
var search = function (keyword) {
var keywordCounts = getChars((0, hangul_js_1.disassemble)(keyword).join(''));
var founds = [];
itemCounts.map(function (itemCount, index) {
var matchCount = 0;
Object.entries(itemCount).map(function (_a) {
var itemKey = _a[0], itemValue = _a[1];
Object.entries(keywordCounts).map(function (_a) {
var keywordKey = _a[0], keywordValue = _a[1];
if (itemKey === keywordKey && itemValue >= keywordValue)
matchCount += keywordValue;
});
});
if (matchCount !== 0)
founds.push([items[index], matchCount]);
});
return founds.sort(function (min, max) { return max[1] - min[1]; });
};
return search;
};
exports.createSearch = createSearch;
var search = (0, exports.createSearch)(['롯데시네마', '유튜브', '프로게이머']);
var result = search('시ㄴ');
console.log(result);