DEV Community

Cover image for Function Composition Explained Using Pokémon Evolution

Function Composition Explained Using Pokémon Evolution

Cat on May 28, 2020

Yo, (scarf) dog. I heard you like functions, so I put a function in ur function so that you can function while it functions. < / oldMemes >&...
Collapse
 
shimphillip profile image
Phillip Shim

Nice, this is the beauty of JavaScript. Passing in functions as arguments make the language to do some interesing stuff..

Also not relevant to composition but using switch statement is better inside eevee function since there are more than 2 different conditionals.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Higher order functions are not unique to JavaScript tho, so it's just a really nice feature.

Collapse
 
shimphillip profile image
Phillip Shim

Good to know :)

Collapse
 
cat profile image
Cat

True. I wanted to use the switch function, but since my friend was a complete newbie and was already inundated with all the info, I stuck with what she knew: if/else. lol

Collapse
 
essheck profile image
essheck

I'm new to Dev world as well, And your example was explained really well, But I didn't understand why the Evolution function needs a second argument in it's definition.. As we are prompting the user to input the second argument.

Collapse
 
cat profile image
Cat

I was under the thought that I needed a “holder” for the prompt so we can pass that through the individual Pokémon function to get their evolution result.

Also, I wanted to help my friend meet assignment requirements, which asked for 2 arguments.

But, I should definitely try it out without the second parameter.

Collapse
 
vonheikemen profile image
Heiker

This is the best game ever
*article

Collapse
 
cat profile image
Cat • Edited

Ohhh my god lmao those 3 idiots.
Image of ROFLMAOing Pikachu

Collapse
 
miketalbot profile image
Mike Talbot ⭐

I loved this. Absolutely loved it. But I'm pretty sure I need a lie down - never was any good at Pokemon :)

Collapse
 
cat profile image
Cat

I can't even with the latest stuff with "IV"s and shiny hunting stuff these days. But I'm glad you enjoyed the article!!

Collapse
 
dailydevtips1 profile image
Chris Bongers

Awesome wat of explaining this!

Collapse
 
cat profile image
Cat

Thank you!!!

Collapse
 
ananeridev profile image
Ana Beatriz • Edited

OMGGGG I loved, I love explain things using pokemon too, your article was very good, I will share it with the people of the Brazilian communities <3 Tnkss Cat

Collapse
 
adrianbruhnardo profile image
Adrian Bernardo

I always forget that .map(), .split(), .join(), and .reverse() are examples of function compositions. But your Pokemon references really helped me understand them more!

Collapse
 
cat profile image
Cat

I'm glad it helped!! :)