Skip to content

Instantly share code, notes, and snippets.

@Announcement
Created February 11, 2020 17:23
Show Gist options
  • Save Announcement/47457dff2d7313f959611c6b761f0a9b to your computer and use it in GitHub Desktop.
Save Announcement/47457dff2d7313f959611c6b761f0a9b to your computer and use it in GitHub Desktop.
what's the correct way to document this function?
function * count() {
const maximum =
(arguments.length === 1 && typeof arguments[0] === "number") ? arguments[0] :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("maximum")) ? arguments[0].maximum :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("max")) ? arguments[0].max :
(arguments.length === 2 || arguments.length === 3) ? arguments[1] : 0;
const minimum =
(arguments.length === 1 && typeof arguments[0] === "number") ? 0 :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("minimum")) ? arguments[0].minimum :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("min")) ? arguments[0].min :
(arguments.length === 2 || arguments.length === 3) ? arguments[0] : 0;
const increment =
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("increment")) ? arguments[0].increment :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("inc")) ? arguments[0].inc :
(arguments.length === 3) ? arguments[2] : (maximum > minimum ? 1 : -1);
for (let i = 0, I = (Math.max(minimum, maximum) - Math.min(minimum, maximum)) / Math.abs(increment); i <= I; i++) {
yield i * increment + minimum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment