Skip to content

Instantly share code, notes, and snippets.

@icylace
Last active November 18, 2024 19:53
Show Gist options
  • Save icylace/b08864bdd734139a87c63556ba46a2b9 to your computer and use it in GitHub Desktop.
Save icylace/b08864bdd734139a87c63556ba46a2b9 to your computer and use it in GitHub Desktop.
A JavaScript Challenge -- The Array of Randomness

A JavaScript Challenge -- The Array of Randomness

Write a function called deez() which creates and returns an array of random length whose items are random numbers.

Example usage and output:

console.log(deez())
// [0.8029792178993878, 0.9291390188438964]

console.log(deez())
// [0.33210968307150557]

console.log(deez())
// [0.8937903294523319, 0.38640098414032686, 0.758686960140309, 0.3845423409997013]

However, the following constraints MUST be respected:

  1. Use only vanilla JavaScript and no other language or framework.
  2. Avoid bracket notation (e.g. let ligma = [], squeal[69], !+([])).
  3. Avoid prototype/static methods from Array, TypedArray, and their subclasses (e.g. Array.prototype.push(), Int8Array.from()).
  4. Avoid any other prototype/static methods that create arrays (e.g. String.prototype.split()).
  5. Avoid array constructors (e.g. Array(), Int8Array()).
  6. Avoid arrays from JSON (e.g. JSON.parse("[1, 2, 420]")).
  7. Avoid arrays from regex results (e.g. "registered\r\nnurse\r\n".match(/(?=(.+))\1/g)).
  8. Avoid array-like objects (e.g. arguments, { 0: "Brazil", 1: "mentioned" }).
  9. Avoid looping keywords (e.g. for, while, do...while).
  10. deez() must not call itself.
  11. Avoid using the Y combinator.
  12. deez() must be a pure function (aside from random number generation).
  13. deez() must produce fresh output every time it is called.
  14. deez().length > 0 must always be true.
  15. deez().every(Number.isFinite) must always be true.
  16. Use dynamically generated randomness, not xkcd randomness.
  17. eval() is allowed...

Link: https://gist.github.com/icylace/b08864bdd734139a87c63556ba46a2b9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment