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";
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] validate code with simple regex (8 kyu) / JavaScript (0) | 2023.04.27 |
---|---|
[Codewars] Regex count lowercase letters (8 kyu) / JavaScript (0) | 2023.04.27 |
[Codewars] Find the first non-consecutive number (8 kyu) / JavaScript (0) | 2023.04.26 |
[Codewars] Simple validation of a username with regex (8 kyu) / JavaScript (0) | 2023.04.25 |
[백준] 26529: Bunnies / Node.js (JavaScript) (0) | 2023.04.25 |
댓글