Tanweer Profile picture
Aspiring Software Developer 👨‍💻

Feb 24, 2022, 10 tweets

💡 JavaScript Tip 💡
Making a 'composition function' becomes much more cleaner✨
#javascript #webdevelopment
Here's how👇

Normally while composing functions, you would do this👇which is okay, but when you are using too many functions, the code become hard to read

Follow these steps👇 to make your composition cleaner and more scalable

Step 1⃣
Install a package called 'lodash' in your project.
run 👇 in your terminal

Step 2⃣
Import the function in your JavaScript file
Do this on top of your file👇

Step 3⃣
Write any two(not necessarily) function:
I'm gonna make functions called 'trim' and 'toLowerCase' 👇

Step 4⃣
Call the 'pipe' function by passing all of your func names in their executing sequence. 'pipe' returns a function which takes the input and passes through the series of function in such a way that the result from first function is passed into the next function

Step 5⃣
Now console log the result. You should see this👇

That's all for now.

If you found this helpful, make sure to

1. Like & Retweet the first tweet so others will also learn

2. Follow @roc_tanweer to see more useful content

See you guys next time👋
Happy Coding🤓

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling