Count the Number of Digits - JavaScript Logic Simplified 👉 Day 24 / Day 93👈 👉 Find how many digits a number has — without converting it to a string? 1️⃣ Handle 0 as a special case — it has 1 digit. 2️⃣ Use Math.abs() to support negative numbers. 3️⃣ Repeatedly divide the number by 10 until it becomes 0, increasing the counter each time. 💡 Example: 👉 23453 → 2345 → 234 → 23 → 2 → 0 ✅ Total digits = 5 #JavaScript #CodingTips #WebDevelopment #FrontendDeveloper #LearnToCode #ProgrammingLogic #CleanCode #ProblemSolving #100DaysOfCode #TechCommunity #CodeNewbie #Algorithms
How to Count Digits in a Number with JavaScript Logic
More Relevant Posts
-
🗓️ Day 21 of JS Series by Rohit Negi 📔 What I Learned: ✅ What a prototype is ✅ How the prototype chain works ✅ The concept of inheritance using prototypes ✅ How JavaScript can provide property and method suggestions even if they aren’t explicitly defined (because of the prototype chain) ✅ In JavaScript, almost every data type (except null and undefined) is derived from the Object type ✅ Learned the basics of OOP (Object-Oriented Programming) concepts in JavaScripttype (except null and undefined) is derived from the Object type. ✅ Learn Oops concept #JavaScript #WebDevelopment #LearnInPublic
To view or add a comment, sign in
-
-
“Daily Temperatures” Using Stack in JavaScript ♨️ 👉 Day 19 / Day 93 👈 Description: 👉 The goal is to find out how many days you have to wait until a warmer temperature. ✅ Approach: 👉 Traverse the array from right to left. 👉Maintain a stack to store indices of temperatures in decreasing order. 👉 For each day, pop all smaller or equal temperatures. 👉 The difference between the current index and top of stack gives the number of days to wait. This method ensures O(n) time complexity instead of a brute-force O(n²). #JavaScript #CodingChallenge #DSA #InterviewPreparation #FrontendDeveloper #ProblemSolving #100DaysOfCode #TechLearning #LeetCode #Algorithms
To view or add a comment, sign in
-
-
Day - 27🚀 📘 DSA Practice: 1️⃣ Reverse Vowels of a String – #345 2️⃣ Two Sum II (Input Array Sorted) – #167 💻 JavaScript Learning: Explored the behavior of the this keyword across different contexts — global scope, objects, functions, and event listeners. Also learned how to use call, apply, and bind to control function context effectively. #100DaysOfCode #JavaScript #DSA #FrontendDevelopment #LearningJourney #CodingDaily #TechGrowth
To view or add a comment, sign in
-
Javascript Logic Challenge #2 — Reverse a Number Goal: Write a JavaScript program to reverse a number. Example: Input: 1234 Output: 4321 Step-by-Step : 1. Pick the last digit (using % 10) 2. Add it to a new number (reverse) 3. Remove the last digit (using Math.floor(num / 10)) 4. Keep doing it until no digits are left Every small code teaches me something new . guess the output #JavaScript #LogicBuilding #WebDevelopment #CodingJourney #FrontendDeveloper #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Learning Matrix Manipulation in JavaScript Today I learned how to handle matrices in JavaScript! I implemented a function called zeroMatrix() that sets entire rows and columns to 0 if any element in the matrix is 0. This helped me understand how nested loops, logical conditions, and 2D arrays work together — a great hands-on exercise for improving problem-solving skills in JS. #JavaScript #CodingJourney #WebDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
Day 3 – JavaScript Loops Practice In this task, I practiced different types of JavaScript loops — for, while, do...while, and for...of — to understand how iteration works in programming. I applied loops to solve small problems like counting numbers, iterating over arrays, and displaying patterns in the console. This practice improved my logic-building skills, debugging techniques, and understanding of flow control in JavaScript. Key Learning Areas: Difference between for, while, and do...while loops Using loops with arrays and objects Avoiding infinite loops and understanding loop conditions Real-time testing using console.log() #JavaScript #WebDevelopment #FrontendLearning #CodingChallenge #Loops #CodingJourney #WomenInTech #100DaysOfCode
To view or add a comment, sign in
-
Day 8 of #30DaysOfJavaScript on LeetCode Today's challenge: 2629 — Function Composition The task was to implement a function that takes an array of functions [f1, f2, f3, ..., fn] and returns a new function that represents their composition. In simple terms, the composed function should apply all the given functions from right to left, just like: f(g(h(x))) Here’s my solution 👇 var compose = function(functions) { return function(x) { let res = x; for (let i = functions.length - 1; i >= 0; i--) { res = functions[i](res); } return res; } }; This challenge gave me a deeper understanding of how function chaining and composition work in JavaScript — building complex logic from smaller, reusable functions. It’s a beautiful example of how functional programming principles simplify problem-solving! Try it out here : https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #30DaysOfCode #Functions #Callbacks #Programming #Composition
To view or add a comment, sign in
-
-
Day 4 of #30DaysOfJavaScript on LeetCode Today's challenge: 2665 — Counter II 🔁 The task was to create a createCounter function that accepts an initial integer init and returns an object with three functions: increment() → increases the value by 1 decrement() → decreases the value by 1 reset() → resets the value back to init Here’s my solution 👇 var createCounter = function(init) { let cache = init; return { increment: function() { return ++init; }, reset: function() { init = cache; return cache; }, decrement: function() { return --init; } }; }; This challenge was a good exercise in understanding closures and object methods — it’s cool how functions can maintain state in JavaScript! 💡 If you’d like to try it out, check it here: https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #Closures #30DaysOfCode #Functions #Objects #Programming
To view or add a comment, sign in
-
-
Syntax Trap #001 Hey there 👋 I've spent a lot of time learning the details of JavaScript and stumbled across lots of surprising gotchas that only became clear after understanding what's going on under the hood. I plan to post one of these each day (or so) and would love to get discussions around the specific "problems". Here's the first: What's the result? const num = '5'; console.log("5" * 4 + num); Error 25 205 55555 Easy, right :) .. said some of my coworkers, before getting it wrong 🤓 https://lnkd.in/g6KefEgc
To view or add a comment, sign in
-
Syntax Trap #001 Hey there 👋 I've spent a lot of time learning the details of JavaScript and stumbled across lots of surprising gotchas that only became clear after understanding what's going on under the hood. I plan to post one of these each day (or so) and would love to get discussions around the specific "problems". Here's the first: What's the result? const num = '5'; console.log("5" * 4 + num); Error 25 205 55555 Easy, right :) .. said some of my coworkers, before getting it wrong 🤓 https://lnkd.in/g6KefEgc
To view or add a comment, sign in
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