Untitled
unknown
plain_text
a month ago
4.5 kB
2
Indexable
Never
// 3. Do all requires that based on three variables as below const companies = [ { name: "Company One", category: "Finance", start: 1981, end: 2004 }, { name: "Company Two", category: "Retail", start: 1992, end: 2008 }, { name: "Company Three", category: "Auto", start: 1999, end: 2007 }, { name: "Company Four", category: "Retail", start: 1989, end: 2010 }, { name: "Company Five", category: "Technology", start: 2009, end: 2014 }, { name: "Company Six", category: "Finance", start: 1987, end: 2010 }, { name: "Company Seven", category: "Auto", start: 1986, end: 1996 }, { name: "Company Eight", category: "Technology", start: 2011, end: 2016 }, { name: "Company Nine", category: "Retail", start: 1981, end: 1989 }, ]; const ages = [33, 12, 20, 16, 5, 54, 21, 44, 61, 13, 15, 45, 25, 64, 32]; const person = { name: "Costas", address: { street: "Lalaland 12", }, }; // • Print the name of each company using forEach // • Print the name of each company that started after 1987 // • Get only the companies that have category Retail, increment their start by 1 and append in the DOM a div that has the name, the category, the start and the end in paragraphs elements // • Sort the companies based on their end date in ascending order // • Sort the ages array in descending order // • Print the sum if you add all the ages using reduce // • Make a new object that has the properties of name and category same as the companies [0] and a method print that prints out the name, use object restructuring and ES6 JS // • Create a function that takes an unknown number of arguments that are numbers and return their sum; // • Make a function that takes an unknown number of arguments of any type and adds them in an array and returns the array, if the argument is an array, it should add its values to the array that will be returned by the function // • Destructuring the property street in a variable named street from the object person // • Write a function that every time you call it, it returns a number that increments starting from 0 // • Create a function that destructors the query parameters of a URL and adds them in an object as key value pairs and then returns the object export default function () { function print() { let { name } = companies[0]; return name; } function sum(...args) { return args.reduce((total, item) => (total += item), 0) } return ( <> <h3>Print the name of each company using forEach</h3> {companies.map(({ name }, index) => ( <div key={index}>{name}</div> ))} <h3>Print the name of each company that started after 1987</h3> {companies .filter(({ start }) => start > 1987) .map(({ name }, index) => ( <div key={index}>{name}</div> ))} <h3> Get only the companies that have category Retail, increment their start by 1 and append in the DOM a div that has the name, the category, the start and the end in paragraphs elements </h3> <table style={{}}> <tbody> {companies .filter(({ category }) => category === "Retail") .map(({ name, start, end }, index) => ( <tr key={index}> <td>{name}</td> <td>{start}</td> <td>{end}</td> </tr> ))} </tbody> </table> <h3>Sort the companies based on their end date in ascending order</h3> {[...companies] .sort((first, second) => first.end - second.end) .map(({ name, end }, index) => ( <div key={index}> {name}:{end} </div> ))} <h3>Print the sum if you add all the ages using reduce</h3> {ages.reduce((total, item) => (total += item), 0)} <h3> Make a new object that has the properties of name and category same as the companies [0] and a method print that prints out the name, use object restructuring and ES6 JS </h3> {print()} <h3> Make a function that takes an unknown number of arguments of any type and adds them in an array and returns the array, if the argument is an array, it should add its values to the array that will be returned by the function </h3> {sum(...ages)} </> ); }
Leave a Comment