A thread on Swapping two numbers using #Javascript.
What? You thought we always need a 3rd variable for it? Believe me there are at least 4 more ways to do that..
https://abs.twimg.com/emoji/v2/... draggable="false" alt="😅" title="Lächelndes Gesicht mit offenem Mund und Angstschweiß" aria-label="Emoji: Lächelndes Gesicht mit offenem Mund und Angstschweiß">
#100DaysOfCode #CodeNewbie #code @thackingschool @codedotin @iprashanth_ #CodingTips #bootcamp
What? You thought we always need a 3rd variable for it? Believe me there are at least 4 more ways to do that..
#100DaysOfCode #CodeNewbie #code @thackingschool @codedotin @iprashanth_ #CodingTips #bootcamp
Let& #39;s get it out of our system first
https://abs.twimg.com/emoji/v2/... draggable="false" alt="😜" title="Winking face with tongue" aria-label="Emoji: Winking face with tongue">. Undoubtedly the most common way to swap two numbers. But where& #39;s the fun in it right?
#100DaysOfCode #CodePen #javascript
#100DaysOfCode #CodePen #javascript
Idea is simple, get the sum of the two numbers. The numbers can then be swapped by subtracting from the sum. #simple
https://abs.twimg.com/emoji/v2/... draggable="false" alt="🤭" title="Gesicht mit Hand über dem Mund" aria-label="Emoji: Gesicht mit Hand über dem Mund">
But wait, there& #39;s more...
#100DaysOfCode #Swap #codinglife
But wait, there& #39;s more...
#100DaysOfCode #Swap #codinglife
It& #39;s basic arithmetic. Dividing the product by any of the operand will always give you the other operand.. Isn& #39;t it?
Yes, there are flaws to this approach, like what if one of the number is 0, right? But who said this is the best approach?
https://abs.twimg.com/emoji/v2/... draggable="false" alt="😜" title="Winking face with tongue" aria-label="Emoji: Winking face with tongue"> I didn& #39;t!
#programming #codingisfun
Yes, there are flaws to this approach, like what if one of the number is 0, right? But who said this is the best approach?
#programming #codingisfun
This one is cool! Remember our old friend XOR? He& #39;s all grown up and is helping us do cool stuffs
https://abs.twimg.com/emoji/v2/... draggable="false" alt="😋" title="Face savouring food" aria-label="Emoji: Face savouring food">. Cant blame you if you don& #39;t remember, but he returns 1 if the corresponding bits of two operands are opposite. XOR is weird, it literally can& #39;t even #PunIntended
#100DaysOfCode
#100DaysOfCode
Finally, here& #39;s XNOR. Whatever XOR does, he does the opposite (Rivals! I tell you
https://abs.twimg.com/emoji/v2/... draggable="false" alt="🤦🏻♂️" title="Mann schlägt sich die Hand vors Gesicht (heller Hautton)" aria-label="Emoji: Mann schlägt sich die Hand vors Gesicht (heller Hautton)">). But they both can get the work done.
#CodingTips #100DaysOfCode #programming
#CodingTips #100DaysOfCode #programming
Wow! You read it so far.. Here& #39;s a joke for you.
What did the Owner of a 7-bit dog say?
"Don& #39;t worry, it doesn& #39;t byte!"
https://abs.twimg.com/emoji/v2/... draggable="false" alt="😂" title="Gesicht mit Freudentränen" aria-label="Emoji: Gesicht mit Freudentränen">
#sorrynotsorry #Dontunfollowme
What did the Owner of a 7-bit dog say?
"Don& #39;t worry, it doesn& #39;t byte!"
#sorrynotsorry #Dontunfollowme