3liYusuf / js-objects-lab

0 stars 0 forks source link

Can also use .reduce #6

Open KhalilKhunji opened 2 months ago

KhalilKhunji commented 2 months ago

https://github.com/3liYusuf/js-objects-lab/blob/27bc3d2301bd3029c9d81608b81de9a5647c6b91/app.js#L384-L392

This problem is a classic case for using the .reduce method. Like so:

const pokemonTypes = pokemon.reduce((accumulator, poke) => { 
  accumulator[poke.type] ? accumulator[poke.type].push(poke) : accumulator[poke.type] = [poke];
  return accumulator;
}, {});

Great job on this lab + Level up! Only real mistake was in the sorting, so nicely done!

3liYusuf commented 2 months ago

Thank you Khalil for the great feedback!