8 kyu
Be Concise I - The Ternary Operator
5,902 of 8,109donaldsebleung
Description:
Be Concise I - The Ternary Operator
You are given a function describeAge
/ describe_age
that takes a parameter age
(which will always be a positive integer) and does the following:
- If the age is
12
or lower, itreturn "You're a(n) kid"
- If the age is anything between
13
and17
(inclusive), itreturn "You're a(n) teenager"
- If the age is anything between
18
and64
(inclusive), itreturn "You're a(n) adult"
- If the age is
65
or above, itreturn "You're a(n) elderly"
Your task is to shorten the code as much as possible. Note that submitting the given code will not work because there is a character limit of 137.
I'll give you a few hints:
- The title itself is a hint - if you're not sure what to do, always research any terminology in this description that you have not heard of!
- Don't you think the whole
"You're a(n) <insert_something_here>"
is very repetitive? ;) Perhaps we can shorten it? - Write everything in one line,
\n
and other whitespaces counts.
Whatever you do, do not change what the function does. Good luck :)
Fundamentals
Refactoring
Similar Kata:
Stats:
Created | Mar 24, 2016 |
Published | Mar 24, 2016 |
Warriors Trained | 12817 |
Total Skips | 181 |
Total Code Submissions | 69222 |
Total Times Completed | 8109 |
JavaScript Completions | 5902 |
CoffeeScript Completions | 17 |
Ruby Completions | 228 |
Java Completions | 1044 |
Python Completions | 1126 |
Total Stars | 122 |
% of votes with a positive feedback rating | 84% of 1580 |
Total "Very Satisfied" Votes | 1217 |
Total "Somewhat Satisfied" Votes | 229 |
Total "Not Satisfied" Votes | 134 |