Code Monkey home page Code Monkey logo

javascript-greatest-pokemons's Introduction

LAB - Greatest Pokemon

Introduction

This lab includes another testing library called as Jasmine. Try self-learning. Completing this lab gives you a special badge for this week.

We have just learned some super useful methods, that will help us a lot to manipulate objects and arrays. In this exercise, we will focus on practicing them, and this being said, it is mandatory to implement at least one of them in each iteration.

Best way to practice is to work with real data. In the src/data.js file you will find an array of info about all the pokemons in your pokedex

Requirements

  • Fork this repo

  • Clone this repo

  • Practice JavaScript advanced methods (map, forEach, reduce, filter and sort to manipulate arrays)

Submission

  • Upon completion, run the following commands:

  

git add .

  

git commit -m "done"

  

git push origin master

  

  • Don't create a Pull Request. This is only for practice. Just make sure Jasmine is happy :)

Introduction

The src/data.js contains an array of pokemons. Here is one example of how the data is displayed:

  

{

  

"id": 1,

  

"num": "001",

  

"name": "Bulbasaur",

  

"img": "http://www.serebii.net/pokemongo/pokemon/001.png",

  

"type": [

  

"Grass",

  

"Poison"

  

],

  

"height": "0.71 m",

  

"weight": "6.9 kg",

  

"candy": "Bulbasaur Candy",

  

"candy_count": 25,

  

"egg": "2 km",

  

"spawn_chance": 0.69,

  

"avg_spawns": 69,

  

"spawn_time": "20:00",

  

"multipliers": [

  

1.58

  

],

  

"weaknesses": [

  

"Fire",

  

"Ice",

  

"Flying",

  

"Psychic"

  

],

  

"next_evolution": [

  

{

  

"num": "002",

  

"name": "Ivysaur"

  

},

  

{

  

"num": "003",

  

"name": "Venusaur"

  

}

  

]

  

},

  

In the next a couple of iterations, you will be using your JS knowledge to manipulate with this data.

Tests!

Ohh yes! We have our beloved tests, but we have used Jasmine in this lab and not Jest. You don't have to install or run anything using npm. Open the SpecRunner.html file on your browser with Live Server and voila, that's it, your tests should show up and now you can start coding to pass the tests. Remember to focus on one test at a time and read carefully the instructions to understand what you have to do. The tests can be found in the tests/pokemons.spec.js file.

Instructions

You have to work on the src/pokemons.js file.

Iteration 1: All Fire Pokemons

We need to get the array of all Fire type pokemons. Go ahead and create a function named getAllFirePokemons() that receives an array of pokemons as an argument and returns a new filtered array.

"type": [

"Fire",

],

All fire type pokemons will have that type Fire

Iteration 2: Find the Shortest Pokemon?

Go ahead and create a shortestPokemon() function that receives an array as a parameter and returns the name of the shortest pokemon

Iteration 3: All candy_count average

Create a candyAverage() function that receives an array as a parameter. This function must return the average of candy_count for all the pokemons

The average must be returned rounded to 2 decimals! Note: Some pokemons do not have a candy_count. Handle that scenario gracefully.

๐Ÿ’ก Maybe you want to "reduce" the data to a single value. ๐Ÿ˜‰

Iteration 4: Get the images for the first 10 Ground Pokemons

Create a function getGroundPokeImg() which accepts an array of pokemons as a parameter and returns an array of images for the first 10 Ground type pokemons.

Note: Ground type pokemons have this property in the object


"type": [

"Ground",

],

Iteration 5: Find all pokemon names heavier than Pikachu

We might need to use more than a single loop here

Create a function getHeavyPokemons() that receives an array as parameter and returns a new filtered array with the names of all Pokemons heavier than Pikachu.

Note: All pokemons have a weight attribute. You moght need to use that

๐Ÿ’ก Make sure not to mutate the original array ๐Ÿ˜‰

Iteration 6: Alphabetic order

Create a orderAlphabetically() function, that receives an array and returns an array of first 20 pokemons, alphabetically ordered based on their name. Return only the name of each pokemon, and if the array you receive has less than 20 pokemons, return all of them.

๐Ÿ’ก Make sure not to mutate the original array ๐Ÿ˜‰

Iteration 7: Strong pokemons

Create a strongPokemons() function, that receives an array and returns an array of first 15 pokemon names, that have just one weakness

Happy coding! โค๏ธ

javascript-greatest-pokemons's People

Contributors

abernier avatar manishpoduval avatar mjarraya avatar papuarza avatar sandrabosk avatar vijayaadamane avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.