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, it return "You're a(n) kid"
If the age is anything between 13 and 17 (inclusive), it return "You're a(n) teenager"
If the age is anything between 18 and 64 (inclusive), it return "You're a(n) adult"
If the age is 65 or above, it return "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 :)
// describeAge(9) // => "You're a(n) kid"
// describeAge(10) // => "You're a(n) kid"
// describeAge(11) // => "You're a(n) kid"
// describeAge(12) // => "You're a(n) kid"
// describeAge(13) // => "You're a(n) teenager"
// describeAge(14) // => "You're a(n) teenager"
// describeAge(15) // => "You're a(n) teenager"
// describeAge(16) // => "You're a(n) teenager"
// describeAge(17) // => "You're a(n) teenager"
// describeAge(18) // => "You're a(n) adult"
// describeAge(19) // => "You're a(n) adult"
// describeAge(63) // => "You're a(n) adult"
// describeAge(64) // => "You're a(n) adult"
// describeAge(65) // => "You're a(n) elderly"
// describeAge(66) // => "You're a(n) elderly"
// describeAge(100) // => "You're a(n) elderly"
describeAge = a => {
//write your code here
}
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
Write function RemoveExclamationMarks which removes all exclamation marks from a given string.
function removeExclamationMarks(s) {
}
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(removeExclamationMarks("Hello World!"), "Hello World");
// Test.assertEquals(removeExclamationMarks("Hello World!!!"), "Hello World");
// Test.assertEquals(removeExclamationMarks("Hi! Hello!"), "Hi Hello");
// Test.assertEquals(removeExclamationMarks(""), "");
// Test.assertEquals(removeExclamationMarks("!"), "");
});
});
Create a function that takes a string and returns the number of vowels in that string.
function vowels(str) {
//code here
}
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});