Grouping distinct items
Description:
The goal of this exercise is to transform a flat array into one grouped by category. Each item in the array is an object with the following shape:
const original = {
_distinctSeqID: number,
category: string,
otherThings
}
The goal at the end is to create an array of objects for each of the categories, where each object has the following shape:
const final = {
distinctAttribute: string,
results: [
objects, // the complete original objects
],
}
The array will be already sorted by category. This means that you might have one or multiple objects of the same category, but each category will only occur once, there won't be repetitions afterwards.
The _distinctSeqID
is an incrementing id starting at 0 for a new category, and then augmenting each time an object of the same category comes up.
Lastly, note that the key "category" is customizable in the function. This is the key that is used for grouping, which your function doesn't need to handle. Just the fact that the attributeForDistinct
will the the same as the key you want to have top-level as marker for looping over.
If you enjoyed this kata, you can also check out groupBy
Similar Kata:
Stats:
Created | Jul 26, 2018 |
Published | Jul 28, 2018 |
Warriors Trained | 273 |
Total Skips | 45 |
Total Code Submissions | 368 |
Total Times Completed | 88 |
JavaScript Completions | 88 |
Total Stars | 0 |
% of votes with a positive feedback rating | 81% of 37 |
Total "Very Satisfied" Votes | 25 |
Total "Somewhat Satisfied" Votes | 10 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 28 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |