Skip to content

Instantly share code, notes, and snippets.

@hannahhch
Last active July 26, 2023 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save hannahhch/0023133f175b465088eeff0cad47b230 to your computer and use it in GitHub Desktop.
Save hannahhch/0023133f175b465088eeff0cad47b230 to your computer and use it in GitHub Desktop.

Gear Maintenance

const gear = {
  camping: [
    {
      item: 'tent',
      condition: 'good'
    },
    {
      item: 'sleeping bag',
      condition: 'bad'
    },
    {
      item: 'flashlight',
      condition: 'excellent'
    }
  ],
  climbing: [
    {
      item: 'climbing shoes',
      condition: 'bad'
    },
    {
      item: 'harness',
      condition: 'good'
    }
  ],
  kayaking: [
    {
      item: 'kayak',
      condition: 'okay'
    },
    {
      item: 'life jacket',
      condition: 'excellent'
    },
    {
      item: 'dry bag',
      condition: 'bad'
    }
  ]
};

Level One

Write a function that will return an array of all items that are in bad condition.

['sleeping bag', 'climbing shoes', 'dry bag' ]

Level Two

Refactor your function so that we can keep track of which activity the bad condition item is associated with.

[
  { camping: 'sleeping bag' },
  { climbing: 'climbing shoes' },
  { kayaking: 'dry bag' }
]

Level Three

Refactor your function so that the gear is organized by condition.

{
  good: [
    { item: 'tent', activity: 'camping' },
    { item: 'harness', activity: 'climbing' }
  ],
  bad: [
    { item: 'sleeping bag', activity: 'camping' },
    { item: 'climbing shoes', activity: 'climbing' },
    { item: 'dry bag', activity: 'kayaking' }
  ],
  excellent: [
    { item: 'flashlight', activity: 'camping' },
    { item: 'life jacket', activity: 'kayaking' }
  ],
  okay: [ { item: 'kayak', activity: 'kayaking' } ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment