Skip to content

Instantly share code, notes, and snippets.

@ctjlewis
Last active June 17, 2020 08:04
Show Gist options
  • Save ctjlewis/e201e0b89074f9bde630c32ff5b43fc8 to your computer and use it in GitHub Desktop.
Save ctjlewis/e201e0b89074f9bde630c32ff5b43fc8 to your computer and use it in GitHub Desktop.
function* range(n) {
let i = 0;
while (i++ < n)
yield i;
}
Array.prototype.sum = function () {
return this.reduce((a, b) => Number(a) + Number(b));
}
Array.prototype.avg = function () {
return this.sum() / this.length;
}
for (let i of range(10))
console.log(i);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment