JavaScript Codewars Kata: European Floor Conversion

🚀 Codewars Kata Reflection: “What’s the Real Floor?” (8 kyu, JavaScript) Today I revisited a deceptively simple Codewars challenge that reinforced an important lesson: clarity in problem modeling beats complexity in code. 🧠 The problem American and European floor numbering systems differ: In the US, the 1st floor is actually the ground floor There is no 13th floor Basements (negative floors) remain unchanged The task was to convert an American floor number into its European equivalent. 💡 Why the solution works function getRealFloor(n) { return n <= 0 ? n : n < 13 ? n - 1 : n - 2; } This works because it mirrors the real-world rules directly: Basements (n <= 0) These are universal - no transformation needed. Floors 1-12 Since “1” maps to ground floor, all values shift down by 1. Floors above 13 Two numbers are missing below them: Floor 1 (ground floor) Floor 13 So we shift down by 2. Instead of looping or mapping values, the logic is handled with simple conditional branching, making the intent obvious and the behavior predictable. ⚡ Time & Space Complexity Time Complexity: O(1) - constant time, no loops, no recursion Space Complexity: O(1) - no additional memory allocated. 📚 What I learned 1. Not every problem needs iteration - sometimes rules are enough 2. Writing code that reflects real-world constraints leads to simpler solutions 3. Even beginner-level katas are great for sharpening logic, edge-case thinking, and code expressiveness. Small challenges, big reminders. On to the next kata 🧩💪 #Codewars #JavaScript #ProblemSolving #CleanCode #SoftwareEngineering #LearningInPublic #Algorithms

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories