This folder contains JavaScript exercises focused on algorithmic thinking and numerical problem solving. These labs emphasize logical reasoning, performance awareness, and step-by-step evaluation of conditions to produce correct results.
The focus moves beyond simple data manipulation and into designing procedures that efficiently solve computational problems.
More algorithm-focused practice labs will be added here as learning progresses.
This lab calculates the sum of all prime numbers up to a given limit. It demonstrates how helper functions, mathematical rules, and loop-based evaluation combine to solve a number-theory problem efficiently.
sumPrimes(10) โ 17
sumPrimes(5) โ 10
sumPrimes(1) โ 0
.reduce()This lab introduces structured algorithm design where correctness and efficiency both matter. Instead of operating on provided data, the function generates results through systematic evaluation and rule-based logic. It reinforces the importance of decomposition, mathematical reasoning, and clear procedural flow โ all foundational skills for advanced programming.
This lab calculates the smallest number that is evenly divisible by every integer within a given inclusive range. It demonstrates how number theory concepts and helper functions work together to solve a compound divisibility problem efficiently.
smallestCommons([1, 5]) โ 60
smallestCommons([2, 10]) โ 2520
smallestCommons([5, 1]) โ 60
This lab strengthens algorithmic thinking by combining multiple mathematical operations into a single solution. Instead of evaluating values independently, the logic progressively builds a result that satisfies increasing constraints. The exercise reinforces decomposition, efficiency, and the relationship between mathematical rules and program structure.
This lab flattens a nested array structure of any depth into a single-level array. It demonstrates how recursion can be used to traverse hierarchical data and extract values regardless of nesting level.
steamrollArray([[["a"]], [["b"]]]) โ ["a", "b"]
steamrollArray([1, [2], [3, [[4]]]]) โ [1, 2, 3, 4]
Array.isArray() for type checksThis lab builds algorithmic reasoning by requiring the function to process data whose structure is not fixed in depth. Instead of relying on iteration alone, recursion enables systematic traversal of nested layers until only individual values remain. The exercise reinforces call stack behavior, decomposition of complex input, and how recursive logic simplifies hierarchical data processing.
This lab evaluates whether all objects in a collection contain a truthy value for a specified property. It demonstrates how higher-order functions and JavaScriptโs truthiness rules can be combined to perform concise logical validation.
truthCheck([{ a: "hello" }, { a: 42 }, { a: [] }], "a") โ true
truthCheck([{ score: 10 }, { score: 0 }, { score: 5 }], "score") โ false
.every() for logical validationThis lab highlights how powerful JavaScriptโs higher-order functions can be when paired with a solid understanding of language semantics. Instead of looping and manually checking conditions, the solution relies on expressive built-in behavior to enforce a rule across a dataset. It reinforces how clarity and correctness often come from using the right abstraction rather than more code.
These labs build algorithmic thinking by focusing on how problems are solved step-by-step rather than how data is stored. Working with numerical logic, helper functions, and efficiency considerations develops the reasoning skills needed for more advanced programming tasks, technical interviews, and performance-sensitive applications.