Bob
This commit is contained in:
24
typescript/bob/bob.ts
Normal file
24
typescript/bob/bob.ts
Normal 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.";
|
||||
}
|
||||
Reference in New Issue
Block a user