Imperative & procedural programming: statements, loops, mutation, procedures
#Imperative code is a sequence of statements that change state: declare a variable, loop, update it, return it. Procedural programming organises those steps into named functions that take inputs and return results. JavaScript is imperative at heart (let, for...of, Map.set), with functional array methods layered on top; TypeScript adds types but no new control flow.
Complete program
Complete program.
In practice: keep mutation local to one function and return the result instead of updating module-level variables; use readonly parameter types so a procedure cannot change its caller's data; reach for a plain loop when it is clearer than a chain of reduce calls.
Money is kept in integer cents: adding floating-point dollars (0.1 + 0.2) drifts.
readonly Order[] stops the procedure from pushing to or sorting the caller's array, but the objects inside are still mutable unless their fields are readonly too.
A Map iterates in insertion order, so the output follows the order categories first appear.