Swapna Kumar Panda ✨ Profile picture
Jan 26 β€’ 10 tweets β€’ 2 min read
How is Math.min() > Math.max() ?

A JavaScript 🧡
➊ Background

⬔ Try to execute below in console.

β‡₯ Math.min() > Math.max()

⬓ You will be surprised to see the result "true".

⬕ How can min() be more than max()? Is it weird?

Let's find out.
βž‹ Variadic Function

⬔ A function is called "variadic" when it can handle variable number of arguments.

⬕ Both Math.min() and Math.max() can handle any number of arguments including "Zero".
➌ How do they operate?

⬔ They try to find the minimum/maximum value among given arguments by comparing 2 consecutive arguments iteratively.

⬕ Comparison operation is performed between 2 arguments and, suitable value is carried over to compare with next argument.
➍ Zero or, One Argument

β¬’ But, how are cases of "Zero" or, "One" argument handled? Because we do not have 2 values to compare between.

⬓ To handle "Zero" or, "One" argument cases, we need to have an initial comparant.
➎ Initial Comparant

β¬’ Initial comparant has to be such a value which when compared to the first argument should always return the first argument.

⬓ In case of zero arguments, value of initial comparant is returned.
➎.βž€ Initial Comparant for Math.min()

β¬– The comparison operation in Math.min() is "<"

⬘ So, initial comparant should never be "<" than the first argument.

β¬— Initial comparant has to be the highest possible number which is "Infinity"
➎.➁ Initial Comparant for Math.max()

β¬– The comparison operation in Math.min() is ">"

⬘ So, initial comparant should never be ">" than the first argument.

β¬— Initial comparant has to be the lowest possible number which is "-Infinity"
➏ Math.min() & Math.max() for "0" arguments

❑ For zero arguments, both returns the initial comparant.

β‡₯ Math.min() ⇨ Infinity
β‡₯ Math.max() ⇨ -Infinity

❒ So, now you got to know why

Math.min() > Math.max()
End of 🧡

Do you find this 🧡 useful? If you are interested in more tutorial threads on JavaScript, React, HTML and, CSS, I am sharing those regularly.

To never miss any, Follow me βœ…

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Swapna Kumar Panda ✨

Swapna Kumar Panda ✨ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @swapnakpanda

Jan 25
SQL & RDBMS Interview Questions

⇩
Series: 1️⃣
Level: Beginner
Topics:

➊ Introduction to RDBMS
βž‹ Normalisation
➌ Introduction to SQL
➍ Tables and Fields
➎ Constraints
➏ DML Operations
➐ Joins
πŸš₯ Disclaimer

β¬– The questions covered here are mostly conceptual
⬘ I never claim only these type of questions are/should be asked during interviews
β¬— For interviews, you should have fundamentals strong. And you should be able to provide solutions to practical problems.
Read 13 tweets
Jan 24
~11000 friends in [CHIRPBIRDICON], 🀩

If you are interested in,

🌐 HTML
🎨 CSS
πŸ‘©β€πŸ’» JavaScript
βš›οΈ React
πŸ›  DSA
πŸ›’ SQL/NoSQL

Follow me βœ…

I am sharing contents daily in [CHIRPBIRDICON] which you won't want to miss. 🧡of pointers to all those, πŸ‘‡
🌐 HTML 🎨 CSS

twitter.com/i/events/14854…
πŸ‘©β€πŸ’» JavaScript

twitter.com/i/events/14854…
Read 7 tweets
Jan 23
πŸ’› CSS: border-radius

Explained with Classic Illustrations
πŸ“‹ Table of Contents

➊ Introduction
βž‹ How to specify?
βž‹.βž€ One/Two/Three/Four Values
βž‹.➁ Percentage Value
βž‹.βž‚ Horizontal and Vertical Radius
➌ Other Related Properties
➍ Shapes using border-radius
➎ Conclusion
➊ Introduction
Read 12 tweets
Jan 22
πŸ“š Books you must read for

πŸ›  DSA
πŸ›’ SQL
🌐 JavaScript

⇩
β¬– Books were and still are the most important medium for our knowledge growth.

⬘ Do you love to read books? How about for technical subjects? If no, I would suggest you should.

β¬— Here, I will list few important ones. If you want to add any, feel free.
πŸ›  DSA

➊ Grokking Algorithms
✍️ Aditya Bhargava

βž‹ Introduction to Algorithms
✍️ Thomas H. Cormen βŠ• Charles E. Leiserson βŠ• Ronald L. Rivest βŠ• Clifford Stein

➌ Introduction to Algorithms
✍️ Udi Manber
Read 9 tweets
Jan 21
There may be a "Hole" in your Array

πŸŸͺπŸŸͺπŸŸͺπŸ•³πŸŸͺπŸŸͺ

A JavaScript 🧡
➊ What is a hole?

β¬’ Holes are indices β€œinside” an Array that have no associated element.

⬔ An array with at least a single hole in it is called a "Sparse Array".

⬓ An array without any hole is called a "Dense Array".
βž‹ How to detect a hole?

Check if

⬙ 0 ≀ index < Array's length
⬘ index is not in the array

Example:

To check if there is a hole at index "2" in "arr" whose length is 5

β‡₯ !(2 in arr)
Read 13 tweets
Jan 19
πŸ’« 100 Inspiring Accounts

If their tweets appeared in your timeline, you would definitely learn something new.

They are experts in

πŸ™ Web Development
πŸŽ‘ UI/UX
πŸ‘©β€πŸ’» Programming
πŸ›’ Database
πŸ›  System Design
πŸ”© Machine Learning
🎯 DSA
β›“ Blockchain
🌐 Web3
Read 8 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(