This example was adapted from Berkeley cs169 under a CC-BY-SA-NC license.
On December 31, 2008, all Microsoft Zune MP3 players that were booted up on that day mysteriously froze. If you rebooted on January 1, 2009, it would work again. This example includes the buggy code, as explained in this blog post, transliterated to ES6. Try 10593 (Dec 31, 2008) or 1827 (Dec 31, 1984) to trigger the bug (an infinite loop). Note that this implies that we start counting from 1, that is January 1 is day 1.
v0.js
: Original transliteratedv1.js
: Refactored with more relevant variable names, but no other changesv2.js
: Extract theisLeapYear
function to improve readability and introduce a test suitev3.js
: ExtractsaddLeapYear
andaddCommonYear
functions to reduce function complexity. Adds additional test cases for extracted functions.v4.js
: Major refactor to fix logic error, add additional tests ot verify correctness.
This package incorporates ESLint, which is configured to flag functions/methods with cyclomatic complexity greater than NIST-recommended limit of 10. None of the examples should trigger that limit. You can modify .eslintrc.json
to implement stricter limits (e.g. 5).
This package also incorporates the Plato code analysis tool to generate complexity and other statistics for each file (and function/method). You can generate the Plato report (a static website in the report
directory) with:
npm run plato
Unfortunately there is not a readily available tool for ABC complexity analysis for ES6.