Skip to content

Instantly share code, notes, and snippets.

@DonBrowny
Last active March 20, 2024 05:21
Show Gist options
  • Save DonBrowny/e0f4f280804ddd3e29b3bb5b3278bb49 to your computer and use it in GitHub Desktop.
Save DonBrowny/e0f4f280804ddd3e29b3bb5b3278bb49 to your computer and use it in GitHub Desktop.

For the below exercises please create a pull request(PR) for each exercise. For each pull request keep theParthe , sriramramanathan and DonBrowny as reviewers

Use the below pokemon object as an input for excersie 9,10 & 11

Use the below pokemon & pokemonDescription for exercise 12

const pokemon = [
    {
        "id": 1,
        "name": "bulbasaur",
        "height": 7,
        "weight": 69,
        "types": [
            {
                "slot": 1,
                "type": {
                    "name": "grass",
                    "url": "https://pokeapi.co/api/v2/type/12/"
                }
            },
            {
                "slot": 2,
                "type": {
                    "name": "poison",
                    "url": "https://pokeapi.co/api/v2/type/4/"
                }
            }
        ]
    },
    {
        "id": 2,
        "name": "ivysaur",
        "height": 10,
        "weight": 130,
        "types": [
            {
                "slot": 1,
                "type": {
                    "name": "grass",
                    "url": "https://pokeapi.co/api/v2/type/12/"
                }
            },
            {
                "slot": 2,
                "type": {
                    "name": "poison",
                    "url": "https://pokeapi.co/api/v2/type/4/"
                }
            }
        ]
    },
    {
        "id": 3,
        "name": "venusaur",
        "height": 20,
        "weight": 1000,
        "types": [
            {
                "slot": 1,
                "type": {
                    "name": "grass",
                    "url": "https://pokeapi.co/api/v2/type/12/"
                }
            },
            {
                "slot": 2,
                "type": {
                    "name": "poison",
                    "url": "https://pokeapi.co/api/v2/type/4/"
                }
            }
        ]
    },
    {
        "id": 4,
        "name": "charmander",
        "height": 6,
        "weight": 85,
        "types": [
            {
                "slot": 1,
                "type": {
                    "name": "fire",
                    "url": "https://pokeapi.co/api/v2/type/10/"
                }
            }
        ]
    },
    {
        "id": 5,
        "name": "charmeleon",
        "height": 11,
        "weight": 190,
        "types": [
            {
                "slot": 1,
                "type": {
                    "name": "fire",
                    "url": "https://pokeapi.co/api/v2/type/10/"
                }
            }
        ]
    },
    {
        "id": 6,
        "name": "charizard",
        "height": 17,
        "weight": 905,
        "types": [
            {
                "slot": 1,
                "type": {
                    "name": "fire",
                    "url": "https://pokeapi.co/api/v2/type/10/"
                }
            },
            {
                "slot": 2,
                "type": {
                    "name": "flying",
                    "url": "https://pokeapi.co/api/v2/type/3/"
                }
            }
        ]
    },
    {
        "id": 7,
        "name": "squirtle",
        "height": 5,
        "weight": 90,
        "types": [
            {
                "slot": 1,
                "type": {
                    "name": "water",
                    "url": "https://pokeapi.co/api/v2/type/11/"
                }
            }
        ]
    },
    {
        "id": 8,
        "name": "wartortle",
        "height": 10,
        "weight": 225,
        "types": [
            {
                "slot": 1,
                "type": {
                    "name": "water",
                    "url": "https://pokeapi.co/api/v2/type/11/"
                }
            }
        ]
    },
    {
        "id": 9,
        "name": "blastoise",
        "height": 16,
        "weight": 855,
        "types": [
            {
                "slot": 1,
                "type": {
                    "name": "water",
                    "url": "https://pokeapi.co/api/v2/type/11/"
                }
            }
        ]
    },
    {
        "id": 10,
        "name": "caterpie",
        "height": 3,
        "weight": 29,
        "types": [
            {
                "slot": 1,
                "type": {
                    "name": "bug",
                    "url": "https://pokeapi.co/api/v2/type/7/"
                }
            }
        ]
    }
]
const pokemonDescription = [
    {
        "id": 1,
        "description": "Loves to eat"
    },
    {
        "id": 2,
        "description": "Proud of its power"
    },
    {
        "id": 3,
        "description": "Sturdy body"
    },
    {
        "id": 4,
        "description": "Highly curious"
    },
    {
        "id": 5,
        "description": "Strong willed"
    },
    {
        "id": 6,
        "description": "Likes to run"
    },
    {
        "id": 7,
        "description": "Takes plenty of siestas"
    },
    {
        "id": 8,
        "description": "Likes to thrash about"
    },
    {
        "id": 9,
        "description": "Capable of taking hits"
    },
    {
        "id": 10,
        "description": "Mischievous"
    }
]

Exercise 9: Create a javascript function that will sort the pokemons based on the weight in ascending order.

Exercise 10: Create a javascript function that accepts two args pokemons and desiredHeight. This function returns an array of pokemons which have height greater than or equal to the desiredHeight

Exercise 11: Create a javascript function that accepts two args pokemons and desiredType. This function returns an array of pokemons which have type equal to the desiredType

Exercise 12: Create a javascript function that combines the pokemon and the pokemonDescription (mentioned at the bottom) so the resulting array is of the below format

[
  { id: 1, name: 'bulbasaur', description: 'Loves to eat' },
  { id: 2, name: 'ivysaur', description: 'Proud of its power' },
  // ... and so on
]

Exercise 13: Create a javascript function that converts the pokemonDescription to a single object of the below format

{
  1 : { id: 1, name: 'bulbasaur', description: 'Loves to eat' },
  2 : { id: 2, name: 'ivysaur', description: 'Proud of its power' },
  // ... and so on
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment