---
id: 699d20623e57e8ffee88545c
title: Step 17
challengeType: 1
dashedName: step-17
---

# --description--

Now you'll build `groupByDecade`, which organizes the catalog by decade. Each key will be a string like `"1970s"` and each value an array of books from that period.

Create a function named `groupByDecade` that takes `catalog` as a parameter. Inside, declare `const grouped = {}`. Add a `for` loop to iterate over `catalog`, and inside the loop declare `const book = catalog[i]`.

# --hints--

You should have a function named `groupByDecade` with a `catalog` parameter.

```js
const regex = __helpers.functionRegex('groupByDecade', ['catalog']);
assert.match(__helpers.removeJSComments(code), regex);
```

You should declare a variable named `grouped` set to an empty object.

```js
assert.match(groupByDecade.toString(), /(const|let|var)\s+grouped\s*=\s*\{\s*\}/);
```

You should use a `for` loop to iterate over `catalog`.

```js
assert.match(groupByDecade.toString(), /for\s*\(\s*(var|let)\s+(\w+)\s*=\s*0\s*;\s*\2\s*<\s*catalog\s*\.\s*length\s*;\s*\2\+\+\s*\)\s*\{/);
```

You should declare a variable named `book` set to the current catalog entry.

```js
assert.match(groupByDecade.toString(), /(const|let|var)\s+book\s*=\s*catalog\[/);
```

# --seed--

## --seed-contents--

```js
const rawCatalogCards = [
  "From a Buick 8 | King, Stephen | 2002 | Shelf K7",
  "The Shining | King, Stephen | 1977 | Shelf K1",
  "The Stand | King, Stephen | 1978 | Shelf K2",
  "It | King, Stephen | 1986 | Shelf K3",
  "Misery | King, Stephen | 1987 | Shelf K4",
  "Do Androids Dream of Electric Sheep? | Dick, Philip K. | 1968 | Shelf D5",
  "I, Robot | Asimov, Isaac | 1950 | Shelf A8",
  "Foundation | Asimov, Isaac | 1951 | Shelf A9",
  "Dune | Herbert, Frank | 1965 | Shelf H3",
  "Neuromancer | Gibson, William | 1984 | Shelf G8",
  "Snow Crash | Stephenson, Neal | 1992 | Shelf S6",
  "The Martian | Weir, Andy | 2011 | Shelf W5",
  "Ender's Game | Card, Orson Scott | 1985 | Shelf C2",
  "The Hitchhiker's Guide to the Galaxy | Adams, Douglas | 1979 | Shelf A1",
  "Ready Player One | Cline, Ernest | 2011 | Shelf C7",
  "The Dark Tower: The Gunslinger | King, Stephen | 1982 | Shelf K5",
  // edge cases: missing data
  "Unknown Title |  | 1975 | Shelf X1",
  "Mysterious Manuscript | Unknown Author |  | Shelf Z9",
  "Ancient Scroll | Anonymous | 850 | ",
];

function parseCard(rawString) {
  const parts = rawString.split("|");
  const trimmedParts = [];
  for (let i = 0; i < parts.length; i++) {
    trimmedParts.push(parts[i].trim());
  }
  const title = trimmedParts[0];
  const author = trimmedParts[1];
  const year = trimmedParts[2];
  const location = trimmedParts[3];
  return {
    title: title || "Unknown",
    author: author || "Unknown",
    year: year ? parseInt(year) : "Unknown",
    location: location || "Unknown"
  };
}

function parseCatalog(rawCards) {
  const catalog = [];
  for (let i = 0; i < rawCards.length; i++) {
    catalog.push(parseCard(rawCards[i]));
  }
  return catalog;
}

const catalog = parseCatalog(rawCatalogCards);

function findByAuthor(catalog, author) {
  const searchTerm = author.toLowerCase();
  const results = [];
  for (let i = 0; i < catalog.length; i++) {
    if (catalog[i].author.toLowerCase().includes(searchTerm)) {
      results.push(catalog[i]);
    }
  }
  return results;
}

--fcc-editable-region--

--fcc-editable-region--
```
