Skip to content

Instantly share code, notes, and snippets.

@kaylagordon
Last active April 12, 2024 16:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save kaylagordon/2c407d05d697efe7b6667e9b0711d51e to your computer and use it in GitHub Desktop.
Save kaylagordon/2c407d05d697efe7b6667e9b0711d51e to your computer and use it in GitHub Desktop.

Crafting

const craftSupplies = {
  crossStitching: [
    { name: 'fabric', amountNeeded: 0.25 }, 
    { name: 'needle', amountNeeded: 1 }, 
    { name: 'thread', amountNeeded: 10 }, 
    { name: 'scissors', amountNeeded: 1 },
    { name: 'hoop', amountNeeded: 1 }
  ],
  weaving: [
    { name: 'loom', amountNeeded: 1 }, 
    { name: 'needle', amountNeeded: 1 }, 
    { name: 'yarn', amountNeeded: 6 }, 
    { name: 'scissors', amountNeeded: 1 }
  ],
  knitting: [    
    { name: 'needle', amountNeeded: 2 }, 
    { name: 'yarn', amountNeeded: 4 }, 
    { name: 'scissors', amountNeeded: 1 }
  ],
  crocheting: [
    { name: 'hook', amountNeeded: 1 }, 
    { name: 'yarn', amountNeeded: 3 }, 
    { name: 'scissors', amountNeeded: 1 }
  ]
};

Level One

Write a function that takes in a parameter of craft and returns a list of supplies needed

getSupplyList('crossStitching') 
// --> ['fabric', 'needle', 'thread', 'scissors', hoop]

getSupplyList('crocheting') 
// --> ['hook', 'yarn', 'scissors']

Level Two 🌶

Write a function that returns a list of supplies with associated crafts

viewSupplies()  
// --> 
// {
//   fabric: ['crossStitching'],
//   needle: ['crossStitching', 'weaving', 'knitting'],
//   thread: ['crossStitching'],
//   scissors: ['crossStitching', 'weaving', 'knitting', 'crocheting'],
//   hoop: ['crossStitching'],
//   loom: ['weaving'],
//   yarn: ['weaving', 'knitting', 'crocheting']
//   hook: ['crocheting'] 
// }

Level Three 🌶

Refactor your viewSupplies function to include the total amount needed for each supply

viewSupplies() 
// --> 
// {
//   fabric: { crafts: ['crossStitching'], amountNeeded: 0.25 },
//   needle: { crafts: ['crossStitching', 'weaving', 'knitting'], amountNeeded: 0.25 },
//   thread: { crafts: ['crossStitching'], amountNeeded: 4 },
//   scissors: { crafts: ['crossStitching', 'weaving', 'knitting', 'crocheting'], amountNeeded: 4 },
//   hoop: { crafts: ['crossStitching'], amountNeeded: 1 },
//   loom: { crafts: ['weaving'], amountNeeded: 1 },
//   yarn: { crafts: ['weaving', 'knitting', 'crocheting'] amountNeeded: 13 },
//   hook: { crafts: ['crocheting'],  amountNeeded: 1 },
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment