-
Notifications
You must be signed in to change notification settings - Fork 0
Exercises
Receives an object obj.
Shows in the console the name and type of each property in the object.
Example:
const o = {a: 1, b: 'Thor', c: [1,2,3], d: {x: 10}}
showProperties(o)
// Output:
// a: number
// b: string
// c: object
// d: objectReceives an array funcArray.
Executes all functions present in the array, assuming they do not receive parameters.
Example:
function sayHi() { console.log('Hi') }
function sayBye() { console.log('Bye') }
executeFunctions([sayHi, sayBye])
// Output:
// Hi
// ByeReceives an array products (objects with at least a price property) and a number minPrice.
Returns a new array containing only the products whose price is greater than minPrice.
Example:
const products = [
{name: 'Apple', price: 5},
{name: 'Orange', price: 10},
{name: 'Banana', price: 3}
]
const expensive = filterProduct(products, 4)
// expensive: [
// {name: 'Apple', price: 5},
// {name: 'Orange', price: 10}
// ]Receives an array products.
Returns a new array containing only the names of the products.
Example:
const products = [
{name: 'Apple', price: 5},
{name: 'Orange', price: 10},
{name: 'Banana', price: 3}
]
const names = mapProduct(products)
// names: ['Apple', 'Orange', 'Banana']Receives an array products.
Returns the total sum of the prices of all products.
Example:
const products = [
{name: 'Apple', price: 5},
{name: 'Orange', price: 10},
{name: 'Banana', price: 3}
]
const total = reduceProduct(products)
// total: 18Receives a string array in propNames and an object in obj.
Returns a new object with the properties from obj whose names are present in propNames.
If propNames contains names that do not exist in obj, those properties are not added to the returned object.
Example:
const o = {a: 1, b: 'Thor', c: [1,2,3], d: {x: 10}, e: 2, f: 'Captain America'}
const props = ['b', 'd', 'g', 'a']
const oFiltered = filterProperties(props, o)
// oFiltered: {a: 1, b: 'Thor', d: {x: 10}}Receives a string array in propNames and an object array in objs.
Returns a new object array with objects produced by applying the filterProperties function with propNames to each object in objs.
NOTE: In this implementation, you should avoid the usage of any cycle instruction (for/while) or the Array.forEach.
Example:
const objs = [
{a: 1, b: 'Thor', c: [1,2,3], d: {x: 10}, e: 2, f: 'Captain America'},
{b: 'Hulk', a: [1,2,3], d: {x: 10}, e: 2, g: false},
{x: 'Vision', y: false}
]
const props = ['b', 'd', 'g', 'a']
const objsFiltered = filterPropertiesN(props, objs)
/*
objsFiltered: [
{a: 1, b: 'Thor', d: {x: 10}},
{b: 'Hulk', a: [1,2,3], d: {x: 10}, g: false},
{ }
]
*/Include the two functions from Exercise 1.6 and 1.7 in an ECMAScript module so that they can be imported and reused.
Create a separate module containing example code that imports this module and demonstrates how to call the functions.
Write a set of unit tests for the function in Exercise 1.7 using the Mocha testing framework.
The tests should verify that the function behaves correctly with various inputs, including edge cases.
Write a JavaScript function that overrides the default console.log behavior so that every message logged to the console is automatically prefixed with the current date and time.
Note: You can use Date() to get a string with the current date and time in the default format.
Example:
console.log("Hello, world!");Output:
Mon Sep 15 2025 10:42:30 GMT+0000 (Coordinated Universal Time) - Hello, world!