Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,5 @@ server.listen(port, () => {
console.log(`Server is listening for events.`);
console.log("Press Ctrl + C to quit.");
});

// Just adding a comment here to test the review agent
78 changes: 78 additions & 0 deletions src/random.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// randomFunctions.ts

/**
* Generates a random integer between two values (inclusive).
* @param min - The minimum value.
* @param max - The maximum value.
* @returns A random integer between min and max.
*/
function getRandomInt(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

/**
* Returns a random element from an array.
* @param array - The array from which to pick a random element.
* @returns A random element from the array.
*/
function getRandomElement<T>(array: T[]): T {
const randomIndex = getRandomInt(0, array.length - 1);
return array[randomIndex];
}

/**
* Generates a random color in hex format.
* @returns A string representing a random hex color.
*/
function getRandomColor(): string {
const randomColor = `#${Math.floor(Math.random() * 16777215).toString(16)}`;
return randomColor;
}

/**
* Reverses a given string.
* @param input - The string to reverse.
* @returns The reversed string.
*/
function reverseString(input: string): string {
return input.split('').reverse().join('');
}

/**
* Waits for a specified amount of time and then resolves a promise.
* @param ms - The number of milliseconds to wait.
* @returns A promise that resolves after the specified time.
*/
function delay(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}

/**
* Logs a random "fact" to the console after a delay.
*/
async function logRandomFact() {
const facts: string[] = [
"Honey never spoils.",
"Bananas are berries.",
"Wombat poop is cube-shaped.",
"Octopuses have three hearts.",
"A day on Venus is longer than a year on Venus!"
];

await delay(2000); // Wait for 2 seconds
const randomFact = getRandomElement(facts);
console.log(`Random Fact: ${randomFact}`);
}

// Example usage
const randomInt = getRandomInt(1, 100);
const randomElement = getRandomElement(['apple', 'banana', 'orange']);
const randomColor = getRandomColor();
const reversedString = reverseString("Hello, TypeScript!");

console.log(`Random Integer: ${randomInt}`);
console.log(`Random Element: ${randomElement}`);
console.log(`Random Color: ${randomColor}`);
console.log(`Reversed String: ${reversedString}`);

logRandomFact();