Skip to content

chore(02): correction step 2 - algorithmics#4

Open
fabernovel-fnguyen wants to merge 1 commit into02_algorithmicsfrom
02_correction
Open

chore(02): correction step 2 - algorithmics#4
fabernovel-fnguyen wants to merge 1 commit into02_algorithmicsfrom
02_correction

Conversation

@fabernovel-fnguyen
Copy link
Collaborator

No description provided.

@fabernovel-fnguyen fabernovel-fnguyen changed the title 02 correction chore(02): correction step 2 - algorithmics Mar 28, 2025
this.httpClient
.get(`type/${pokemonType}`)
.then(
(response) => response.body as unknown as GetPokemonTypeResponse,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pour éviter le as unknown as GetPokemonTypeResponse ici, on peut mettre le type dans le .get 🙂

    const pokemonWithCommonTypes = await Promise.all(
      types.map((pokemonType) =>
        this.httpClient
          .get<GetPokemonTypeResponse>(`type/${pokemonType}`)
          .then((response) => response.body),
      ),
    );

et on peut extraire le body directement dans le then 🙂

          .then(({ body }) => body),


type GetPokemonTypeResponse = {
pokemon: {
pokemon: {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Pourquoi pokemon dans pokemon ? 🤔 Est-ce qu'on ne peut pas faire autrement ? 🤔

Ce serait bien si on pouvait avoir:

    type GetPokemonTypeResponse = {
      pokemon: {
        name: string;
        url: string;
      }[];
    };

Si on change dans cette PR, il faudra modifier aussi dans l'énoncé de la 1ère PR d'algo 🙂

);

// Step 2: Remove any non-first generation pokemon from the array of pokemons
const firstGenerationPokemons = pokemonWithCommonTypes.map(({ pokemon }) =>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might have: On pourrait remplacer le map par un flatMap ici, pour éviter de faire le flat plus bas 🙂

const numberOfSameTypePokemons = sameTypePokemonStats.length;

return sameTypePokemonStats.reduce(
(acc: PokemonStats, pokemon) => ({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

là aussi, on peut extraire stats de pokemon pour réduire le nombre de pokemon.stats. plus bas 🙂

(acc: PokemonStats, { stats }) => ({

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants