SEW | JavaScript Basics
- Implement proper error handling.
As a bank employee, I want to use a coin converter app, so that I can save time and serve more customers.
- The function
convert(amount)
is available, which converts a given amount of cent into as few as possible coins (currency: Euro). - The result is a
Map
, where the keys are coin values and the values are the quantity of each coin. Example:Map(5) { 100 => 1, 50 => 1, 20 => 2, 5 => 1, 2 => 2 }
- Only used values are represented within the resulting Map.
As a security expert I want to encrypt and decrypt strings, so that I can have a secure conversation with my counterpart.
- A function rot13(text) is available.
- The given string is encrypted using the ROT13 method.
- Upper- and lower-case are kept.
- Letters and signs outside of the English alphabet are kept.
- If the argument is no string, it needs to be converted into a string.
- If the function is used twice on a string, it should produce the same string again.
As a content creator I need an easy to use system to sort an array in lexical order, so that I can created sorted list much faster.
- A function is available with two parameters: an array of strings and a boolean flag for the sort order.
- The parameter for the sort order is optional and defaults to ascending.
- The result is an array consisting of the same strings as the input array, only sorted in lexical order.
- If the first parameter is not an array, the function throws a TypeError.
- Hint: take a look at the string method: localeCompare()
As a developer I want to filter an array, so that only even numbers are in the result.
- A function that takes an array of numbers as a parameter is available.
- The result is an array consisting only of even numbers
As a software tester I want to test certain functions, so that I can be sure that they produce the right result.
- A function test(fu, arg, exp) is available, where fu is the function which needs to be tested, arg are the arguments for fu, and exp is the expected return value.
- The function test calls the function fu using arg as argument.
- The return value of fu is compared with exp and if they match true is returned, otherwise false is returned.
As a cool developer I want to create generic code, so that I can be minimize my coding effort.
- A function generate(op) is available.
- The parameter op can be one of the four basic mathematic operations +, -, * or /.
- generate returns a new function, which then can be called with two numbers as parameters.
- The given mathematic operation is performed on the two numbers.
- Example:
- const mult = generate('*')
- console.log(mult(3, 4)) // the value is 12 printed on the console
For a calendar app, I want to implement a general function that extracts all dates from a string.
-A function is available that takes a string as a parameter.
- A regular expression is used to extract all dates matching the DD.MM.YYYY format.
- The function returns an array containing all dates (as strings).