Conteúdo do Curso
JavaScript Data Structures
1. Introduction and Prerequisites
2. Objects Fundamentals
Understanding ObjectsObject CreationNested PropertiesChallenge: Creating an ObjectAccessing Object PropertiesChallenge: Accessing Object PropertiesWorking with PropertiesChallenge: Modifying and Extending ObjectObject MethodsProperties in MethodsChallenge: Working with Object MethodsObject Fundamentals Sum Up
3. Advanced Object Manipulation
JavaScript Data Structures
Challenge: Sorting and Extracting Properties
Task
Given an array of books, each represented by an object with properties (title
, author
, publicationYear
), create a solution that performs the following tasks:
- Sort the array of books:
- Sort by title in ascending order;
- Sort by author in descending order;
- Sort by year in descending order.
- Extract specific properties into separate arrays:
- Create an array containing only the titles of books (sorted by title in ascending order);
- Create an array containing only the authors of books (sorted by author in descending order);
- Create an array containing only the publication years of books (sorted by year in descending order).
Ensure that the original array of books remains unaltered.
Expected output:
- For sorting by title, utilize
localeCompare()
with thetitle
property. - For sorting by author, apply
localeCompare()
with theauthor
property. - For sorting by year, use a numeric comparison based on the
publicationYear
property. - Utilize the
map()
method to create new arrays with specific properties. - Create a callback function for
map()
that returns the desired property for each book. - For extracting titles, authors, and years, the callback functions should return the
title
,author
, andpublicationYear
properties, respectively. - Ensure that the original array of books remains unaltered. Use the spread (
[...books]
) syntax to create a copy for sorting and extracting.
Tudo estava claro?
Seção 5. Capítulo 8
Conteúdo do Curso
JavaScript Data Structures
1. Introduction and Prerequisites
2. Objects Fundamentals
Understanding ObjectsObject CreationNested PropertiesChallenge: Creating an ObjectAccessing Object PropertiesChallenge: Accessing Object PropertiesWorking with PropertiesChallenge: Modifying and Extending ObjectObject MethodsProperties in MethodsChallenge: Working with Object MethodsObject Fundamentals Sum Up
3. Advanced Object Manipulation
JavaScript Data Structures
Challenge: Sorting and Extracting Properties
Task
Given an array of books, each represented by an object with properties (title
, author
, publicationYear
), create a solution that performs the following tasks:
- Sort the array of books:
- Sort by title in ascending order;
- Sort by author in descending order;
- Sort by year in descending order.
- Extract specific properties into separate arrays:
- Create an array containing only the titles of books (sorted by title in ascending order);
- Create an array containing only the authors of books (sorted by author in descending order);
- Create an array containing only the publication years of books (sorted by year in descending order).
Ensure that the original array of books remains unaltered.
Expected output:
- For sorting by title, utilize
localeCompare()
with thetitle
property. - For sorting by author, apply
localeCompare()
with theauthor
property. - For sorting by year, use a numeric comparison based on the
publicationYear
property. - Utilize the
map()
method to create new arrays with specific properties. - Create a callback function for
map()
that returns the desired property for each book. - For extracting titles, authors, and years, the callback functions should return the
title
,author
, andpublicationYear
properties, respectively. - Ensure that the original array of books remains unaltered. Use the spread (
[...books]
) syntax to create a copy for sorting and extracting.
Tudo estava claro?
Seção 5. Capítulo 8