This is my 8th project during my journey at Trybe!
-
The
srcfolder contains all functions -
The
testsfolder contains all tests
Implemented the function average.js and its tests average.spec.js
-
The function
average.jsreceives a array and returns the average of the values received. If the function receives any non-numeric value or an empty array, the valueundefinedis returned, and all results are rounded to integer values. -
The tests
average.spec.jsensure that:- The function returns the average of its values when receiving an array of numbers
- The function returns
undefinedwhen receiving an array containing non-numeric values - The function returns
undefinedwhen receiving an empty array
Implemented the function numbers.js and its tests numbers.spec.js
-
The function
numbersreceives a array and returnstrueif all parameters are of typenumberandfalseotherwise. If the function receives an empty array, the valueundefinedis returned -
The tests
numbers.spec.jsensure that:- The function returns
truewhen receiving an array containing only numeric values - The function returns
falsewhen receiving an array containing non-numeric values - The function returns
undefinedwhen receiving an empty array
- The function returns
Implemented the function circle.js and its tests circle.spec.js
-
The
circlefunction takes the radius of a circle and returns an object containing its information: Radius, Area, and Circumference. If a radius is not specified, the function returnsundefined. -
The tests
circle.spec.jsensure that:- The function returns an object
- Within the return object, it contains the radius, area, and circumference
- The function returns
undefinedif the parameter is not a number or is not passed
Implemented the function createStudent.js and its tests createStudent.spec.js
- The function
createStudentreceives a name as a parameter and returns an object containing two keys:
{
name: 'containing the name passed as a parameter',
feedback: 'containing a function that returns the phrase "Eita pessoa boa!" when called'
}-
The tests
createStudent.spec.jsensure that:- The function returns an object
- Within the return object, it contains the name and feedback
- The function returns
undefinedif the parameter is not passed
Implemented the function productDetails.js and its tests productDetails.spec.js
- The
productDetailsfunction receives a string representing the name of a product and returns an array containing all the objects found indatawhere the name matches the searched name:
productDetails('camisa');Returns:
[
{
name: 'Camisa Gola V',
productId: 456,
},
{
name: 'Camisa Regata',
productId: 112,
}
]-
The tests
productDetails.spec.jsensure that:- The function returns an array
- That the items returned within the array are objects
- That the search is case insensitive
- The function returns
nullif the parameter is not passed
Implemented the function objPlayground.js and its tests objPlayground.spec.js
-
The function
calculatorreceives two integers as parameters and returns the following object:- The results of the divisions are always rounded down
{
sum: // returns the result of the sum of the two numbers,
mult: // returns the result of the multiplication of the two numbers,
div: // returns the result of the division of the two numbers,
sub: // returns the result of the subtraction of the two numbers
}Behavior:
calculator(36, 12); // { sum: 48, mult: 432, div: 3, sub: 24 }-
The function
arrayGeneratorconverts objects into arrays of keys, values, or both. It should receive two parameters:- The first parameter should be a string indicating the type of conversion
- The second parameter should be an object similar to what is returned by the
calculatorfunction
Behavior:
arrayGenerator('keys', { sum: 3, mult: 2, div: 1, sub: 0 })
// [ 'sum', 'mult', 'div', 'sub' ]
arrayGenerator('values', { sum: 3, mult: 2, div: 1, sub: 0 })
// [ 3, 2, 1, 0 ]
arrayGenerator('entries', { sum: 3, mult: 2, div: 1, sub: 0 })
// [ [ 'sum', 3 ], [ 'mult', 2 ], [ 'div', 1 ], [ 'sub', 0 ] ]-
The tests in
objPlayground.spec.jsensure that:- The function
calculatorreturns the correct calculations arrayGenerator(keys, object)returns an array with thekeysof the object passed as a parameterarrayGenerator(values, object)returns an array with thevaluesof the object passed as a parameterarrayGenerator(entries, object)returns an array with theentriesof the object passed as a parameter
- The function
Implemented the function myCounter.js and its tests myCounter.spec.js
-
The function
myCounterhas two nested loops that insert values into an array until its stopping condition. Useful when you need to iterate over a list or matrix in two dimensions or in algorithms that involve multiple iteration, such as depth-first or breadth-first search in a tree, this function can be adapted to generate sequences of iteration steps for analysis and debugging -
The tests in
myCounter.spec.jsensure that:myCounterreturn the expected data according to what is implemented
Implemented the function getCharacter.js and its tests getCharacter.spec.js
- The
getCharacterfunction receives a string parameter representing the name of a fictional character and returns an object containing the character's name, class, and phrases
Example:
getCharacter('Arya');Returns:
{
name: 'Arya Stark',
class: 'Rogue',
phrases: ['Not today', 'A girl has no name.']
}-
The tests in
getCharacter.spec.jsensure that:- The function returns
undefinedif the parameter is not passed - The search is case insensitive
- When receiving a valid string, meaning a character that exists in the database, it returns the correct data
- If passed an invalid string, meaning a character that does not exist in the database, it returns
undefined
- The function returns
Implemented the function restaurant.js and its tests restaurant.spec.js
-
The logic consists of being able to register a menu, and the system should provide an object that allows:
- Reading the registered menu
- Placing orders
- Checking what was ordered
- Summing up the bill
The menu should be registered by separating the foods (food) from the drinks (drink) and should be passed as an object, following the example below:
{
food: {productName: value, productName: value},
drinks: {productName: value, productName: value},
}Obs: the value must be of type number, and decimal places should be separated by a dot, not a comma
Example of usage:
const menuData = {
food: { coxinha: 3.9, sandwich: 9.9 },
drink: { water: 3.9, beer: 6.9 },
};
const menu = createMenu(menuData);
menu.order('coxinha');
menu.order('cerveja');
console.log(menu.consumption); // Should return the array ['coxinha', 'beer']
console.log(menu.pay()); // Should return the value 11.88 (10.80 + 10% tax)-
The tests in
restaurant.spec.jsensure that:createMenu()returns an object that has the keyfetchMenu, which has a function as its value- The menu passed to the
createMenu()function is identical to the menu retrieved by the function'returnedObject.fetchMenu()' returnedObject.consumption, after the menu is created, returns an empty arrayreturnedObject.order()if the value passed as a parameter exists in the menu, it is added to the keyconsumption, if it does not exist, display the message "Item unavailable" and do not change theconsumptionkeyreturnedObject.consumptioncorrectly stores the items ordered through theorderfunction- When calling
returnedObject.pay(), it returns the sum of the prices of everything that was ordered (which is stored in consumption) plus 10% tax