-
-
Save codytowstik/5694cbd05d421e5104748d3707bff3a3 to your computer and use it in GitHub Desktop.
🤖 Example 1 for 'What is Testing?'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// what_is_testing | |
/** | |
* Calculates the number of the specified pokemon caught given a map representing the current Pokedex state. | |
* | |
* @param {{pokemon: string, count: number}} pokedexState the sample Pokedex state | |
* @param {string} pokemonToCount the list of Pokemon to include in the total count | |
* @returns {number} the total specified Pokemon caught | |
*/ | |
let calculateTotalSpecifiedPokemonCaught = ( pokedexState, ...pokemonToCount ) => { | |
let totalPokemonCaught = 0 | |
for ( let index = 0; index < pokemonToCount.length; index++ ) { | |
let currentPokemon = pokemonToCount[ index ] | |
totalPokemonCaught += pokedexState[ currentPokemon ] | |
} | |
console.log(totalPokemonCaught) | |
return totalPokemonCaught | |
} | |
//// sample test data | |
let samplePokedexState = { | |
'Pikachu': 4, | |
'JigglyPuff': 2, | |
'MewTwo': 1, | |
'Bulbasaur': 1 | |
} | |
let sampleEmptyPokedexState = {} | |
//// test calls | |
// empty data parameters | |
calculateTotalSpecifiedPokemonCaught( sampleEmptyPokedexState ) | |
// non-empty Pokedex, looking for Pokemon that exist within the map | |
calculateTotalSpecifiedPokemonCaught( samplePokedexState, 'Pikachu', 'Bulbasaur' ) | |
// non-empty Pokedex, looking for Pokemon that don't exist within the map | |
calculateTotalSpecifiedPokemonCaught( samplePokedexState, 'Vulpix' ) | |
// non-empty Pokedex, looking for some Pokemon that don't exist within the map, and some that do | |
calculateTotalSpecifiedPokemonCaught( samplePokedexState, 'Vulpix', 'Pikachu' ) | |
// 0 | |
// 5 | |
// NaN | |
// NaN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment