Skip to content

Instantly share code, notes, and snippets.

@jonoliver
Last active July 7, 2021 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonoliver/c2ac0a21330722ef2c08531b50032056 to your computer and use it in GitHub Desktop.
Save jonoliver/c2ac0a21330722ef2c08531b50032056 to your computer and use it in GitHub Desktop.
Bob
// Team Reed, Sheridan, Zastrow and Jon
export const hey = (message) => {
if (isEmpty(message)) {
return 'Fine. Be that way!'
}
if (isAllCaps(message) && isQuestion(message)) {
return 'Calm down, I know what I\'m doing!'
}
if (isQuestion(message)) {
return 'Sure.'
}
if (isAllCaps(message)) {
return 'Whoa, chill out!'
}
return 'Whatever.'
};
const isAllCaps = (message) => {
return message.match(/[A-Z]/) && message === message.toUpperCase();
};
const isQuestion = (message) => {
return message.trim().match(/\?$/);
}
const isEmpty = (message) => {
return ! message.match(/\S/);
}
@gtempus
Copy link

gtempus commented Jul 7, 2021

// Team Yosevu, Bryan, and Gary 💥

function isShouting(message) {
  return message.toUpperCase() === message && message !== message.toLowerCase();
}

function isAsking(message) {
  return message.endsWith('?');
}

function isAskingForcefully(message) {
  return isShouting(message) && isAsking(message);
}

export const hey = (message) => {
  let response = 'Whatever.';

  if (isShouting(message)) {
    response = 'Whoa, chill out!';
  }
  
  if (isAsking(message)) {
    response = 'Sure.';
  }

  if (isAskingForcefully(message)) {
    response = "Calm down, I know what I'm doing!";
  }

  return response;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment