build a small practice programme: unit convertor Registry Pattern: Instead of massive if/else chains, I used a lookup object (reg) to define unit types and factors. Base Unit Normalization: I converted everything to a "Base Unit" first (e.g., meters), then to the target. This avoids needing a unique formula for every possible pair (like km -> cm). Type Validation: I added a strict check (from.type !== to.type) to prevent incompatible conversions, like trying to convert Weight to Length. Handling Exceptions: Since Temperature requires offsets (like +32) and not just multiplication factors, I separated it into its own switch case logic. #Javascript #WebDev #LearningInPublic #Coding
Unit Conversion Program in JavaScript
More Relevant Posts
-
Why is JavaScript considered slower compared to Rust? 👉 What actually happens between writing JS and the CPU executing it? That’s when I discovered… it’s all about layers and runtime behavior. 🟡 JavaScript: More Layers Between You and the CPU JavaScript runs inside engines like V8. The flow looks like this: JS Code → Parsing → AST → Bytecode → Interpreter → JIT Compiler → Machine Code → CPU That’s a lot of layers. Each layer adds: Dynamic type checks Garbage collection Runtime optimizations De-optimization when assumptions break JavaScript compiles while running. It’s flexible. But flexibility adds overhead. #JavaScript #Rust #Programming #SoftwareEngineering #WebDevelopment
To view or add a comment, sign in
-
-
It's 5:45 am & I am still looking at my dreams. Today[2/28/2026] is day 23 of learning javascript Today & tommorow i will learn are: 1. Difference between let, const & var 2. How to use the default parameter 3. Template string, Multiline string, Dynamic string 4. Arrow Function Syntax, params 5. Spread Operator, Array Max, Copy Arrays 6. Object & Array destructuring 7. Keys, Values, Entries, Delete, Seal, Freeze 8. Accessing Object Data: Nested Object, Optional Chaining 9. Looping Object 10. Primitive Type, Non Primitive Type 11. Null Vs Undefines 12. Truthy & Falsy Values 13. ==, === , implicit conversion 14. Block Scope, Global Scope, Simple Unders. of Hoisting 15. Closure 16. Callback Function & pass different function 17. Function Arguments, pass by ref. pass by value 18. Map, ForEach 19. Filter, Find, Reduce #letsconnect #programmer #frontenddeveloper #mernstakedeveloper #Coding
To view or add a comment, sign in
-
📌 #62 DailyLeetCodeDose Today's problem: 190. Reverse Bits – 🟢 Easy Bitwise operations, yeah, i know... But actually there is nothing complicated here, we just don't use such operators very often (or don't use it at all :D) Here all operators used in this problem: & – Bitwise AND Compares each bit of two numbers. Returns 1 only if both bits are 1. ex. 5 & 1 (0101 & 0001) → 1 | – Bitwise OR Compares each bit of two numbers. Returns 1 if at least one bit is 1. ex. 4 | 1 (0100 | 0001) → 5 << – Left Shift Shifts all bits to the left. Adds 0 on the right. 🐗 Equivalent to multiplying by 2. ex. 3 << 1 (0011 → 0110) → 6 >>> – Unsigned Right Shift Shifts bits to the right. Adds 0 on the left (ignores sign). ex. 8 >>> 1 (1000 → 0100) → 4 https://lnkd.in/eRJHfQQw #DailyLeetCodeDose #LeetCode #JavaScript #Algorithms #ProblemSolving #Coding
To view or add a comment, sign in
-
-
When Division Is Not Allowed: Thinking in Prefix and Suffix 📊 Solved LeetCode 238 – Product of Array Except Self today. The naive solution would use division, but the constraint pushes you to think differently. The elegant approach: - Build a prefix product array (product of elements to the left) - Build a suffix product pass (product of elements to the right) - Combine them in O(n) time without extra division No nested loops. No division. Linear time. Key takeaway: Many array problems become simple when you think in terms of precomputed cumulative information. 💡 Practical insight: Whenever you see “for each element, compute something excluding itself”, think: - Prefix - Suffix - Two-pass strategy This pattern shows up in range queries, cumulative sums, and DP optimizations. #LeetCode #DSA #Arrays #JavaScript #Algorithms #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
Problem: Longest Substring Without Repeating Characters ✔️ 988 / 988 test cases passed ✔️ Runtime: 3 ms ✔️ Beats 94.57% submissions Approach: This problem is a perfect example of the Sliding Window technique. The idea is to maintain a window of characters that contains no duplicates. 1. Use two pointers (start and end) to represent the window. 2. Use a Set to track characters currently inside the window. 3. Expand the window by moving end. 4. If a duplicate character appears, shrink the window from the left until the duplicate is removed. 5. Keep updating the maximum window size. This way we scan the string only once. Complexity: Time Complexity: O(n) Space Complexity: O(min(n, charset)) Sliding Window is one of those techniques that appears everywhere — strings, arrays, subarrays, and even advanced interview problems. #LeetCode #DSA #SlidingWindow #Algorithms #JavaScript #ProblemSolving #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
Solved another classic Linked List problem today: Swap Nodes in Pairs on LeetCode. Approach: Used a recursive strategy to swap nodes in pairs. Base condition: if the list has 0 or 1 node, return it as is. For each pair: Store the second node. Recursively process the remaining list. Reverse the current pair by updating pointers. Key pointer operations: temp = head.next head.next = swapPairs(head.next.next) temp.next = head Result: Runtime: 0 ms (Beats 100%) Memory: 52.66 MB (Beats 97.59%) Problems like this reinforce how powerful recursion and pointer manipulation are when working with linked lists. #DSA #LinkedList #LeetCode #JavaScript #ProblemSolving #DataStructures #Algorithms #CodingPractice #SoftwareEngineering #BackendDevelopment
To view or add a comment, sign in
-
-
🧠 Day 178 — Next Greater Element 📈 Today I revised one of the most important stack pattern problems in DSA: Next Greater Element. The goal is straightforward but very useful: ✔ For every element, find the next greater element on its right ✔ If no greater element exists → return -1 This problem is a great example of combining: • Stacks • Efficient traversal techniques • Hash map lookups for fast queries Understanding this pattern unlocks solutions to many other problems like Daily Temperatures, Stock Span, and Largest Rectangle in Histogram. 🚀 DSA Journey Update Slowly building strong foundations in Stacks, Dynamic Programming, and Trees. Consistency is the real game. #DSA #Stacks #MonotonicStack #JavaScript #CodingJourney #LeetCode #ProblemSolving #ConsistencyWins
To view or add a comment, sign in
-
-
Problem Solved: Maximum Subarray ✔️ 210 / 210 test cases passed ✔️ Runtime: 2 ms ✔️ Beats 70.71% submissions Key Idea: This problem is a classic application of "Kadane’s Algorithm". Instead of checking every possible subarray (which would take O(n^2), Kadane’s algorithm takes a smarter approach. As we iterate through the array: Keep a running sum of the current subarray. Update the maximum sum whenever a larger value is found. If the running sum becomes negative, reset it to 0 because a negative prefix will only reduce future sums. Complexity: Time Complexity: O(n) Space Complexity: O(1) Every time I revisit these classic algorithms, it reminds me how elegant good algorithm design can be. #LeetCode #DSA #KadaneAlgorithm #JavaScript #CodingJourney #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
-
Object.freeze() VS Object.seal() 👇 - In freeze, object's structure and values are totally locked. existing properties can't be changed or deleted. new properties can't be added. - In seal, only object's structure is locked. existing properties can be changed but not deleted. new properties can't be added. Important Points 👇 - Both freeze and seal are shallow which means they only affect the outer main object and not the nested objects. - The structure and properties of nested objects can still be changed. - To make seal or freeze deep, we have to apply it recursively on all nested objects through functions or loops. Hitesh Choudhary Piyush Garg Chai Aur Code Akash Kadlag Jay Kadlag #JavaScript #WebDevelopment #FrontendDevelopment #WebDev #Coding #Programming #Developer #LearnJavaScript #LearningInPublic #100DaysOfCode #TechCommunity #SoftwareDevelopment #ObjectOrientedProgramming #ChaiAurCode #ReactJS
To view or add a comment, sign in
-
🚀 𝗡𝗲𝘄 𝗣𝗥 𝗠𝗲𝗿𝗴𝗲𝗱 I recently tackled a fun logical puzzle: how to move all zeroes to the end of an array while maintaining the relative order of the non-zero elements. This challenge, which I've documented in my latest PR (https://lnkd.in/dSXWnSES), really tested my ⚙️ 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 to array manipulation. My solution involved iterating through the array and using a pointer to keep track of the position where the next non-zero element should be placed. This allowed me to effectively "compress" the non-zero elements to the front, implicitly leaving zeroes at the end. During the process, I leaned on dry runs to trace the array's state and visualize the pointer movements. When I hit a snag, the debugger was invaluable for stepping through the logic line by line and understanding exactly where my assumptions were off. A key takeaway for me was the power of in-place modification and how a well-placed pointer can simplify array problems significantly. How do you ⚙️ 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 similar array manipulation challenges? Share your strategies below! 📦 Repo: https://lnkd.in/dSXWnSES #ArrayManipulation #JavaScript #Algorithms #ProblemSolving #CodingChallenge #DataStructures #InPlaceAlgorithms #LogicalReasoning #SoftwareDevelopment #LeetCodeStyle
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development