diff --git a/cat.sh b/cat.sh index 65115c3..235b5ed 100755 --- a/cat.sh +++ b/cat.sh @@ -1,3 +1,3 @@ #!/bin/bash -cat dll.js pt.js grid.js binheap.js graph.js proto.js utils.js > out.js +cat dll.js pt.js grid.js binheap.js graph.js proto.js utils.js test.js > out.js diff --git a/out.js b/out.js index 6e1f487..009a268 100644 --- a/out.js +++ b/out.js @@ -225,7 +225,7 @@ class Point { squaredDist(pt) { return this.sub(pt).squaredMag() } dist(pt) { return this.sub(pt).mag() } - + readingOrderCompare(pt) { return this.y < pt.y ? -1 : this.y > pt.y ? 1 : this.x < pt.x ? -1 : this.x > pt.x ? 1 : 0 } copy() { return new Point(this.x, this.y) } @@ -234,6 +234,11 @@ class Point { Pt = Point +function P(...args) { + return new Point(...args) +} + + class Grid { constructor(w, h, fill = 0) { this.width = w @@ -653,8 +658,8 @@ Object.defineProperties(Array.prototype, { } }, sum: { - value: function() { - return this.reduce((a, b) => a + b) + value: function(val) { + return this.reduce((a, b) => a + b, val) } }, flatDeep: { @@ -793,3 +798,4 @@ utils = { createGridArray: (w, h, fill = undefined) => Array(h).fill().map(() => Array(w).fill(fill)) } +console.log(P(0, 0)) diff --git a/proto.js b/proto.js index a8c65af..d2565b6 100644 --- a/proto.js +++ b/proto.js @@ -36,8 +36,8 @@ Object.defineProperties(Array.prototype, { } }, sum: { - value: function() { - return this.reduce((a, b) => a + b) + value: function(val) { + return this.reduce((a, b) => a + b, val) } }, flatDeep: { diff --git a/pt.js b/pt.js index 883ba98..b83014d 100644 --- a/pt.js +++ b/pt.js @@ -53,7 +53,7 @@ class Point { squaredDist(pt) { return this.sub(pt).squaredMag() } dist(pt) { return this.sub(pt).mag() } - + readingOrderCompare(pt) { return this.y < pt.y ? -1 : this.y > pt.y ? 1 : this.x < pt.x ? -1 : this.x > pt.x ? 1 : 0 } copy() { return new Point(this.x, this.y) } @@ -62,3 +62,8 @@ class Point { Pt = Point +function P(...args) { + return new Point(...args) +} + + diff --git a/test.js b/test.js new file mode 100644 index 0000000..e69de29