.
This commit is contained in:
61
proto.js
61
proto.js
@@ -96,6 +96,18 @@ load = function load() {
|
||||
},
|
||||
configurable: true
|
||||
},
|
||||
mapArr: {
|
||||
value: function(fn) {
|
||||
const mapped = new Array(this.length)
|
||||
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
mapped[i] = fn(this[i], i, this)
|
||||
}
|
||||
|
||||
return mapped
|
||||
},
|
||||
configurable: true
|
||||
},
|
||||
sum: {
|
||||
value: function(val = 0) {
|
||||
return this.reduce((a, b) => a + b, val)
|
||||
@@ -122,7 +134,7 @@ load = function load() {
|
||||
},
|
||||
transpose: {
|
||||
value: function() {
|
||||
return Array(this[0].length).fill().map((_, i) => this.map(e => e[i]))
|
||||
return this[0].map((_, i) => this.map(e => e[i]))
|
||||
},
|
||||
configurable: true
|
||||
},
|
||||
@@ -154,7 +166,7 @@ load = function load() {
|
||||
},
|
||||
configurable: true
|
||||
},
|
||||
rotate: {
|
||||
rotateLeft: {
|
||||
value: function(n) {
|
||||
let k = (this.length + n) % this.length
|
||||
return [...this.slice(k), ...this.slice(0, k)]
|
||||
@@ -294,19 +306,13 @@ load = function load() {
|
||||
},
|
||||
configurable: true
|
||||
},
|
||||
map: {
|
||||
value: function(...args) {
|
||||
return this.arr.map(...args)
|
||||
},
|
||||
configurable: true
|
||||
},
|
||||
splitOnElement: {
|
||||
value: function(sep) {
|
||||
let arr = [[]]
|
||||
let arr = [new PointArray()]
|
||||
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
if (this[i].equals(sep)) {
|
||||
arr.push([])
|
||||
arr.push(new PointArray())
|
||||
} else {
|
||||
arr[arr.length - 1].push(this[i])
|
||||
}
|
||||
@@ -316,6 +322,41 @@ load = function load() {
|
||||
},
|
||||
configurable: true
|
||||
},
|
||||
map: {
|
||||
value: function(fn) {
|
||||
const mapped = new PointArray(this.length)
|
||||
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
mapped[i] = fn(this[i], i, this)
|
||||
}
|
||||
|
||||
return mapped
|
||||
},
|
||||
configurable: true
|
||||
},
|
||||
cartProduct: {
|
||||
value: function(that) {
|
||||
return this.flatMap((e) => that.map((f) => new PointArray(e, f)))
|
||||
},
|
||||
configurable: true
|
||||
},
|
||||
interleave: {
|
||||
value: function(that = new PointArray()) {
|
||||
return new PointArray(this, that).transpose().flat()
|
||||
},
|
||||
configurable: true
|
||||
},
|
||||
rotateLeft: {
|
||||
value: function(n) {
|
||||
if (this.length == 1) {
|
||||
return this.copy()
|
||||
}
|
||||
|
||||
let k = (this.length + n) % this.length
|
||||
return new PointArray(...this.slice(k), ...this.slice(0, k))
|
||||
},
|
||||
configurable: true
|
||||
},
|
||||
sort: {
|
||||
value: function(func = (a, b) => a.readingOrderCompare(b)) {
|
||||
return Array.prototype.sort.apply(this, func)
|
||||
|
||||
Reference in New Issue
Block a user