Skip to content

Instantly share code, notes, and snippets.

View Jarvis1010's full-sized avatar

Travis Waith-Mair Jarvis1010

View GitHub Profile
@Jarvis1010
Jarvis1010 / retry.ts
Last active January 26, 2024 01:45
retry
type PromiseFunc<T, K extends unknown = undefined[]> = (
...args: K
) => Promise<T>;
interface Config {
initialDelay?: number;
attempts?: number;
}
function waitFn<T>(fn: PromiseFunc<T>, time: number): Promise<T> {
const collection = [
{ id: 1, name: “Han Solo”, title: “Scruffy Looking Nerf Herder”, allegiance: “rebellion” },
{ id: 2, name: “Darth Vader”, title: “Sith Lord”, allegiance: “empire” },
{ id: 3, name: “K-2SO”, title: “Sass-bot”, allegiance: “rebellion” },
{ id: 4, name: “Wilhuff Tarkin”, title: “Grand Moff”, allegiance: “empire” },
];
var sortedCollection = collection.sort(function(a,b){
return a.name.localeCompare(b.name);
});