Today I practiced one of the classic algorithm problems — implementing the atoi (string to integer) function manually in JavaScript. This problem helps understand: String parsing Handling whitespace and signs Managing integer overflow and boundaries (INT_MAX, INT_MIN) Character to digit conversion using charCodeAt() Here’s a short summary of what my code does: Skips leading spaces Checks for '+' or '-' sign Converts valid numeric characters into an integer Stops at the first invalid character Returns result within 32-bit integer range #JavaScript #CodingChallenge #LeetCode #WebDevelopment #ProblemSolving #LearningJourney
Implemented atoi function in JavaScript for string to integer conversion
More Relevant Posts
-
🚀 𝗗𝗮𝘆 𝟭𝟯 𝗼𝗻 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 Today’s focus was all about mastering sorting and maps in JavaScript two tools that keep showing up everywhere in problem-solving. 🧠 𝗜 𝘀𝗼𝗹𝘃𝗲𝗱: 🔹 344. Reverse String 🔹 977. Squares of a Sorted Array 🔹 242. Valid Anagram 🔹 49. Group Anagrams 💡 𝗞𝗲𝘆 𝘁𝗮𝗸𝗲𝗮𝘄𝗮𝘆: Understanding how sort() and Map() work under the hood makes problems around strings and arrays much easier to tackle. Especially “Group Anagrams” a perfect test for logic and pattern recognition 🧩 #LeetCode #JavaScript #LearnInPublic #BuildInPublic #ProblemSolving #100DaysOfCode #WebDevJourney
To view or add a comment, sign in
-
-
DSA Practice — Day 7 Solved the “Remove Duplicates from Sorted Array” problem on LeetCode. 🧩 Approach: • First, understood the problem statement clearly. • Analyzed the given examples and patterns. • Performed a dry run on paper to visualize the algorithm. • Implemented a pointer-based approach to remove duplicates efficiently. “Clarity before code — that’s how you build problem-solving discipline.” #DSA #LeetCode #ProblemSolving #JavaScript #LearningInPublic #CodingJourney #BackendDeveloper
To view or add a comment, sign in
-
-
DSA Practice — Day 6 Today’s focus was on understanding Time Complexity and Space Complexity — the core of writing efficient algorithms. 🧠 Learned why Big O Notation is used to evaluate performance. ⚙️ Experimented with multiple algorithms to observe how their complexities differ. 📒 Also noted the graphical representation of common Big O complexities in my notebook for quick reference. “Efficiency isn’t about writing less code — it’s about writing code that scales.” #DSA #BigONotation #ProblemSolving #CodingJourney #LearningInPublic #JavaScript #BackendDeveloper
To view or add a comment, sign in
-
Today’s goal: strengthen your string concepts with practice-level questions and real-world logic building in JavaScript. 🔹 Topics for Day 7 : String Manipulation & Logic 1) String traversal using loops 2) String comparison and reversing 3) Counting frequency of characters 4) Checking palindromes and anagrams 4) Removing duplicates or unwanted characters 🧩 Theory Recap str.length → returns string length str[i] → access character at index i str.split('') → converts string to array str.toLowerCase() / str.toUpperCase() → for case conversion str.replace() / str.replaceAll() → replace characters str.includes() → check substring presence str.slice(start, end) → extract part of string
To view or add a comment, sign in
-
💡 JavaScript LeetCode Challenge — Day 19: Longest Common Prefix 🚀 Today’s Challenge: Find the longest common prefix among an array of strings. 🧩 Problem Example: Input: ["flower", "flow", "flight"] Output: "fl" If no common prefix exists, return "". 💭 Key Takeaways: Improved understanding of string manipulation in JavaScript Practiced prefix trimming logic using indexOf() and slice() Every solved problem = better problem-solving muscle 💪 📈 #Day19 #JavaScript #LeetCode #CodingChallenge #100DaysOfCode #WebDevelopment #ProblemSolving #LearningInPublic #CodeNewbie
To view or add a comment, sign in
-
-
💻 JavaScript Conditional Statements (If-Else, Else If, Switch & Ternary) In today’s practice, I explored how JavaScript makes decisions using conditional statements. These help programs respond differently based on input or conditions — just like real-life choices! 🌟 🧩 Covered Concepts: ✅ If–Else: Checking even/odd numbers, eligibility, positive/negative, passwords, divisibility 🧠 Else–If Ladder: Grades, largest number, months, temperature, character types 🔁 Switch Case: Days, seasons, calculator, traffic lights, grades ⚡ Ternary Operator: Quick checks for positivity, largest number, leap year, pass/fail, and case 💬 Practicing these statements improved my logic-building and problem-solving skills in JavaScript! #JavaScript #WebDevelopment #CodingPractice #FrontendDevelopment #LearnToCode #ProgrammingJourney
To view or add a comment, sign in
-
DSA Practice — Day 14 Solved the “Longest Common Prefix” problem today — a classic string-processing question. 🧠 Problem: Given an array of strings, find the longest common prefix among them. If no common prefix exists, return an empty string. At first, I tried multiple pointer-based approaches but kept failing because of tricky edge cases. So I looked at the optimized solution, studied it properly, wrote it down in my notebook, and visualized how the prefix shrinks with each comparison. 🔍 Optimized Logic (Shrinking Prefix Approach) Start with the first string as the initial prefix. Compare it with each string in the list. While the current string doesn’t start with that prefix, keep reducing the prefix length. If prefix becomes empty → return "". Simple, intuitive, and efficient. “Logic becomes simple when you truly understand what the algorithm is doing.” #DSA #Day15 #LeetCode #CodingJourney #ProblemSolving #JavaScript #LearningInPublic #BackendDeveloper
To view or add a comment, sign in
-
-
Day 25/90 – 90 Days DSA Challenge Today I learned how to find the factorial of a number using recursion in JavaScript 💡 🧠 Concept Recap: Recursion is a process where a function calls itself to solve smaller subproblems. In the case of factorial, we multiply the number by the factorial of the previous number until we reach 1. ⚙️ Problem Statement: 👉 Write a recursive function fact(n) that returns the factorial of a number n. 🧩 Example: Input: 5 Process: 5 * 4 * 3 * 2 * 1 Output: 120 Time Complexity: O(n) 💾 Space Complexity: O(n) (recursive call stack) ✨ Key Takeaway: Recursion simplifies problems like factorial by breaking them down into smaller, repeatable steps — clean, simple, and powerful! 🚀 #Day25 #90DaysDSAChallenge #Recursion #JavaScript #ProblemSolving #Factorial #MechCode #LearningInPublic #FrontendDeveloper #CodeEveryday
To view or add a comment, sign in
-
-
🚀 Day 6 of My 30 Days of JavaScript Challenge 🧩 Problem: Filter Elements from Array (LeetCode #2634) Given an integer array arr and a filtering function fn, return a new array filteredArr that only includes elements where fn(arr[i], i) returns a truthy value. Solve this without using the built-in Array.filter() method. 💻 Language: JavaScript ❓ Question: https://lnkd.in/eSGpgXcM 💡 Solution: https://lnkd.in/ekA6y-u3 🧠 Concepts Used: Higher-order functions and callbacks Conditional checks for truthy/falsy values Understanding Boolean(value) behavior in JavaScript 📚 Takeaway: Rebuilding filter() from scratch deepens understanding of conditional logic, iteration, and truthy/falsy evaluation — all essential for functional programming in JavaScript. #Day6 #JavaScript #30DaysOfCode #LeetCode #CodingChallenge #WebDevelopment #FrontendDevelopment #100DaysOfCode
To view or add a comment, sign in
-
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
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