본문 바로가기
알고리즘/Codewars

[Codewars] L1: Bartender, drinks! (8 kyu) / JavaScript

by fluss 2023. 4. 26.

https://www.codewars.com/kata/568dc014440f03b13900001d

 

Codewars - Achieve mastery through coding practice and developer mentorship

A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!

www.codewars.com

 

DESCRIPTION:

Complete the function that receives as input a string, and produces outputs according to the following table:

InputOutput
"Jabroni" "Patron Tequila"
"School Counselor" "Anything with Alcohol"
"Programmer" "Hipster Craft Beer"
"Bike Gang Member" "Moonshine"
"Politician" "Your tax dollars"
"Rapper" "Cristal"
anything else "Beer"

Note: anything else is the default case: if the input to the function is not any of the values in the table, then the return value should be "Beer".

Make sure you cover the cases where certain words do not show up with correct capitalization. For example, the input "pOLitiCIaN" should still return "Your tax dollars".

 

코드

function getDrinkByProfession(param){
  param = param.toLowerCase();
  const list = {
    "jabroni": "Patron Tequila",
    "school counselor": "Anything with Alcohol",
    "programmer": "Hipster Craft Beer",
    "bike gang member": "Moonshine",
    "politician": "Your tax dollars",
    "rapper": "Cristal"
  }
  return list[param] || "Beer";
}

댓글