-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: updated with config/command changes
- Loading branch information
Showing
8 changed files
with
128 additions
and
923 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export function sortBy<T>(arr: T[], fn: (i: T) => sortBy.Types | sortBy.Types[]): T[] { | ||
function compare(a: sortBy.Types | sortBy.Types[], b: sortBy.Types | sortBy.Types[]): number { | ||
a = a === undefined ? 0 : a | ||
b = b === undefined ? 0 : b | ||
|
||
if (Array.isArray(a) && Array.isArray(b)) { | ||
if (a.length === 0 && b.length === 0) return 0 | ||
let diff = compare(a[0], b[0]) | ||
if (diff !== 0) return diff | ||
return compare(a.slice(1), b.slice(1)) | ||
} | ||
|
||
if (a < b) return -1 | ||
if (a > b) return 1 | ||
return 0 | ||
} | ||
|
||
return arr.sort((a, b) => compare(fn(a), fn(b))) | ||
} | ||
export namespace sortBy { | ||
export type Types = string | number | undefined | boolean | ||
} | ||
|
||
export function uniq<T>(arr: T[]): T[] { | ||
return arr.filter((a, i) => { | ||
return !arr.find((b, j) => j !== i && b === a) | ||
}) | ||
} | ||
|
||
export function uniqWith<T>(arr: T[], fn: (a: T, b: T) => boolean): T[] { | ||
return arr.filter((a, i) => { | ||
return !arr.find((b, j) => j !== i && fn(a, b)) | ||
}) | ||
} |
Oops, something went wrong.