25 lines
774 B
TypeScript
25 lines
774 B
TypeScript
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.";
|
|
}
|