Refactor smelly code so it's cleaner without changing what it does: 18 levels of code smells, DRY and KISS, naming and guard clauses.
Refactoring changes the shape of code without changing what it does. In Mrs. Ida's storeroom the old function still stands in the old room, and each delivery (one call with its input) is carried through the old room and your new one: the results must match, for the sealed deliveries too. Tidiness is measured by the ESLint 9 rules this storeroom switches on. A magic number is a raw number whose meaning has to be guessed. By default no-magic-numbers lets a number stand alone as a variable's initial value, a number inside an object or stored to a property, and the radix of parseInt; every other number is reported, 0 and 1 too, because its default ignore list is empty. Mrs. Ida's storeroom sets ignore: [0, 1] and enforceConst: true, so a named number must use const.
Replace Nested Conditional with Guard Clauses (Fowler): the edge cases are handled first with return, and the main path runs straight without indenting. Returning early changes the order the conditions are checked in; that matters only when a condition has a side effect (it calls something that changes state), and the conditions in this storeroom have none. What must stay: the answer for every delivery, the sealed ones too, which carry values you seldom think of.
Extract Function (Fowler): a part with a purpose of its own moves to a named function, and is called. max-statements counts the statements in every { } block of a function, not those of the functions inside it; a statement after an if (…) without braces is not counted, because it is not in a block. What must not change with it: the sum. In JavaScript (a + b) * 5000 is not always the same as a * 5000 + b * 5000.
A row of if checks that only map a value to a value is data. Keep the pairs in an array or an object and read them by key: the branching paths go and complexity drops. switch does not help here, because each case with a value counts too. The table must answer exactly as the ladder did, for keys the ladder never had too.
DRY: the same sum in two places means the next fix has to be remembered in two places. Here the shared part sits in both branches of an if: slide it out of the branches (Fowler calls it Slide Statements, once "Consolidate Duplicate Conditional Fragments"), and the branches keep only what differs. jscpd does not read code as people do. It looks for a run of tokens written exactly alike, names included, as long as min-tokens and across lines; a copy within one line it never reports.
if (c) { return true } else { return false } is the same as return c only when c is already a boolean. A comparison such as >= always gives true or false, so it can be returned directly. A value that is only truthy cannot: return items.length returns 3, not true. De Morgan's laws are the same: inside an if, !(a && b) can be written !a || !b; but a && b on its own returns one of its values, so swapping it for !(!a || !b) turns 3 into true.