Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Sorting and Extracting Properties | Advanced Array Operations
course content

Зміст курсу

JavaScript Data Structures

Challenge: Sorting and Extracting PropertiesChallenge: 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:

  1. Sort the array of books:
    • Sort by title in ascending order;
    • Sort by author in descending order;
    • Sort by year in descending order.
  2. 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:

  1. For sorting by title, utilize localeCompare() with the title property.
  2. For sorting by author, apply localeCompare() with the author property.
  3. For sorting by year, use a numeric comparison based on the publicationYear property.
  4. Utilize the map() method to create new arrays with specific properties.
  5. Create a callback function for map() that returns the desired property for each book.
  6. For extracting titles, authors, and years, the callback functions should return the titleauthor, and publicationYear properties, respectively.
  7. Ensure that the original array of books remains unaltered. Use the spread ([...books]) syntax to create a copy for sorting and extracting.

Все було зрозуміло?

Секція 5. Розділ 8
course content

Зміст курсу

JavaScript Data Structures

Challenge: Sorting and Extracting PropertiesChallenge: 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:

  1. Sort the array of books:
    • Sort by title in ascending order;
    • Sort by author in descending order;
    • Sort by year in descending order.
  2. 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:

  1. For sorting by title, utilize localeCompare() with the title property.
  2. For sorting by author, apply localeCompare() with the author property.
  3. For sorting by year, use a numeric comparison based on the publicationYear property.
  4. Utilize the map() method to create new arrays with specific properties.
  5. Create a callback function for map() that returns the desired property for each book.
  6. For extracting titles, authors, and years, the callback functions should return the titleauthor, and publicationYear properties, respectively.
  7. Ensure that the original array of books remains unaltered. Use the spread ([...books]) syntax to create a copy for sorting and extracting.

Все було зрозуміло?

Секція 5. Розділ 8
some-alt