Skip to content

Instantly share code, notes, and snippets.

View katai5plate's full-sized avatar

Hadhad / HanoHano katai5plate

View GitHub Profile
@katai5plate
katai5plate / groupByPrefix.js
Last active June 19, 2019 01:56 — forked from kurone-kito/groupByPrefix.ts
Group duplicate prefixes in the strings: (src: string[]) => string[]
const getInitials = (src, length) => {
if (length === void 0) { length = 1; }
return Array.from(new Set(src.map(v => v.substring(0, length))));
};
export default src => getInitials(src).map(initial => {
const list = src.filter(v => v.match(`^${initial}`));
const rec = (prev, length) => {
if (length === void 0) { length = 2; }
const _a = getInitials(list, length);
const word = _a[0];