Retired

Filter Map Sort Practice (retired)

Description:

Given a list of Item instances, keep only the items that have a color of "Red" that are LESS than 7 days old.

Once you have the matching items, return the items sorted by Category name (alphabetically, ascending).

class Item {
    String name;
    String color;
    Instant created;
    Integer categoryID;
    Category category; // will be null until you set it
}

enum Category {
  HAZARDOUS, OVERSIZED, FRAGILE, OBLONG, HEAVY
}

Example Input:

// Today is: 2021-07-27T01:32:07.199Z

[
 {
   id: "a1",
   color: "Red",
   created: "2021-07-26T01:32:07.199Z",
   categoryID: 3
 },
 {
   id: "a2",
   color: "Green",
   created: "2021-07-23T01:32:07.199Z",
   categoryID: 1
 },
 {
   id: "a3",
   color: "Red",
   created: "2021-07-25T01:32:07.199Z",
   categoryID: 1
 },
 {
   id: "a4",
   color: "Red",
   created: "2021-07-25T01:32:07.199Z",
   categoryID: 2
 }
]

Expected Output:

[
 {
   id: "a4",
   color: "Red",
   created: "2021-07-01T01:32:07.199Z",
   categoryID: 2 // FRAGILE
 },
 {
   id: "a1",
   color: "Red",
   created: "2021-06-27T01:32:07.199Z",
   categoryID: 3 // OBLONG
 },
 {
   id: "a3",
   color: "Red",
   created: "2021-04-27T01:32:07.199Z",
   categoryID: 1 // OVERSIZED
 },
]
Fundamentals
Filtering
Sorting

More By Author:

Check out these other kata created by oa998

Stats:

CreatedJul 27, 2021
Warriors Trained84
Total Skips2
Total Code Submissions1289
Total Times Completed82
Java Completions82
Total Stars4
% of votes with a positive feedback rating50% of 7
Total "Very Satisfied" Votes3
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes3
Total Rank Assessments7
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • oa998 Avatar
  • ParanoidUser Avatar
Ad