This commit is contained in:
2022-11-05 17:20:19 +01:00
parent d9c3eafba1
commit 942e6bba84
13 changed files with 16381 additions and 0 deletions

24
typescript/bob/bob.ts Normal file
View File

@@ -0,0 +1,24 @@
const isQuestion = (message: string): boolean => message.trim().endsWith("?");
const hasUpperCase = (message: string): boolean =>
Boolean(message.match(/[A-Z]/));
const hasLowerCase = (message: string): boolean =>
Boolean(message.match(/[a-z]/));
const isOnlyUpperCase = (message: string): boolean =>
hasUpperCase(message) && !hasLowerCase(message);
const isEmpty = (message: string): boolean => message.trim() === "";
export function hey(message: string): string {
if (isQuestion(message)) {
if (isOnlyUpperCase(message)) {
return "Calm down, I know what I'm doing!";
}
return "Sure.";
}
if (isOnlyUpperCase(message)) {
return "Whoa, chill out!";
}
if (isEmpty(message)) {
return "Fine. Be that way!";
}
return "Whatever.";
}