was.js

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 29  →  ?path2? @ 28
/trunk/lib/collections/arrays/arrays.js
@@ -1,8 +1,9 @@
/*************************************************************************/
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
function wasProduct(a, b) {
var m = Math.max(a.length, b.length);
function wasProduct(b) {
var a = this;
var m = Math.max(this.length, a.length);
var o = {};
for(var i = 0; i < m; ++i) {
o[a[i]] = b[i];
@@ -10,9 +11,7 @@
return o;
}
if (!Array.prototype.product) {
Array.prototype.product = function(b) {
return wasProduct(this, b);
};
Array.prototype.product = wasProduct;
}
// jQuery
if(typeof jQuery === 'function') {
@@ -24,15 +23,13 @@
/*************************************************************************/
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
function wasStride(a, s) {
return a.filter(function(e, i) {
function wasStride(s) {
return this.filter(function(e, i) {
return i % s === 0;
});
}
if (!Array.prototype.stride) {
Array.prototype.stride = function(s) {
return wasStride(this, s);
};
Array.prototype.stride = wasStride;
}
// jQuery
if(typeof jQuery === 'function') {
@@ -45,17 +42,15 @@
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
// Vanilla JavaScript
function wasChunk(a, n) {
if (!a.length) {
function wasChunk(n) {
if (!this.length) {
return [];
}
return [a.slice(0, n)]
.concat(a.slice(n).wasChunk(n));
return [this.slice(0, n)]
.concat(this.slice(n).wasChunk(n));
}
if (!Array.prototype.chunk) {
Array.prototype.chunk = function(a, n) {
return wasChunk(this, n);
};
Array.prototype.chunk = wasChunk;
}
// jQuery
if(typeof jQuery === 'function') {
@@ -70,25 +65,25 @@
/*stackoverflow.com/questions/7837456/how-to-compare-arrays-in-javascript*/
/*************************************************************************/
// Vanilla JavaScript
function wasEquals(a, b) {
function wasEquals(a) {
// if the other array is a falsy value, return
if (!b) {
if (!a) {
return false;
}
 
// compare lengths - can save a lot of time
if (a.length !== b.length) {
if (this.length !== a.length) {
return false;
}
 
for (var i = 0, l = a.length; i < l; i++) {
for (var i = 0, l = this.length; i < l; i++) {
// Check if we have nested arrays
if (a[i] instanceof Array && b[i] instanceof Array) {
if (this[i] instanceof Array && a[i] instanceof Array) {
// recurse into the nested arrays
if (!a[i].equals(b[i])) {
if (!this[i].equals(a[i])) {
return false;
}
} else if (a[i] !== b[i]) {
} else if (this[i] !== a[i]) {
// Warning - two different object instances will never be equal: {x:20} != {x:20}
return false;
}
@@ -97,9 +92,7 @@
}
if (!Array.prototype.equals) {
// attach the .equals method to Array's prototype to call it on any array
Array.prototype.equals = function(a, b) {
return wasEquals(this, b);
};
Array.prototype.equals = wasEquals;
}
// jQuery
if(typeof jQuery === 'function') {
/trunk/lib/lambda/aggregators.js
@@ -9,7 +9,7 @@
throw "Pairs of predicates expected for cases";
}
(Array.isArray(q) ? q : [ q ]).forEach((s) => {
(Array.isArray(this) ? this : [ this ]).forEach((s) => {
var m = false;
for(var i = 0; i < c.length; i += 2) {
if(!c[i](s)) {
@@ -27,9 +27,7 @@
});
}
if (!Array.prototype.switch) {
Array.prototype.switch = function(d, ...c) {
wasSwitch(this, d, ...c)
};
Array.prototype.switch = wasSwitch;
}
// jQuery
if(typeof jQuery === 'function') {