Skip to content

Instantly share code, notes, and snippets.

View murpyslaw's full-sized avatar

Radoslav Ivanov Ivanov murpyslaw

View GitHub Profile
@murpyslaw
murpyslaw / custom-iterable-objects.ts
Created February 20, 2018 21:16
Matrix is implemented as an object that can be iterated over by a for/of loop, because it produces custom values from it's next() function
class Matrix {
private content: Array<string>;
constructor(public width: number, public height: number, contentFn = (x: number, y: number) => '*') {
this.width = width;
this.height = height;
this.content = [];
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {