diff options
author | 2020-05-19 13:34:38 +0200 | |
---|---|---|
committer | 2020-05-19 13:34:38 +0200 | |
commit | db8f46bf74ffefbbc863f011085903a226f03129 (patch) | |
tree | 20630e9c3c4362b68382231ed859afb11ec5c07e /source/libs/utils.ts | |
parent | 1d87c3d0bd6c8af5286141cf6cff8371ecaeab0f (diff) | |
download | refined-github-db8f46bf74ffefbbc863f011085903a226f03129.tar.gz refined-github-db8f46bf74ffefbbc863f011085903a226f03129.tar.zst refined-github-db8f46bf74ffefbbc863f011085903a226f03129.zip |
Extract `flat-zip`; drop `group-by` (#3107)
Diffstat (limited to 'source/libs/utils.ts')
-rw-r--r-- | source/libs/utils.ts | 32 |
1 files changed, 0 insertions, 32 deletions
diff --git a/source/libs/utils.ts b/source/libs/utils.ts index 88c657af..58eb2368 100644 --- a/source/libs/utils.ts +++ b/source/libs/utils.ts @@ -120,38 +120,6 @@ export const parseTag = (tag: string): {version: string; namespace: string} => { return {namespace, version}; }; -export const groupBy = (iterable: Iterable<string>, grouper: (item: string) => string): Record<string, string[]> => { - const map: Record<string, string[]> = {}; - - for (const item of iterable) { - const key = grouper(item); - map[key] = map[key] ?? []; - map[key].push(item); - } - - return map; -}; - -// Concats arrays but does so like a zipper instead of appending them -// [[0, 1, 2], [0, 1]] => [0, 0, 1, 1, 2] -// Like lodash.zip -export const flatZip = <T>(table: T[][], limit = Infinity): T[] => { - const maxColumns = Math.max(...table.map(row => row.length)); - const zipped = []; - for (let col = 0; col < maxColumns; col++) { - for (const row of table) { - if (row.length > col) { - zipped.push(row[col]); - if (zipped.length === limit) { - return zipped; - } - } - } - } - - return zipped; -}; - export function compareNames(username: string, realname: string): boolean { return username.replace(/-/g, '').toLowerCase() === realname.normalize('NFD').replace(/[\u0300-\u036F\W.]/g, '').toLowerCase(); } |