was.js

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 1  →  ?path2? @ 2
/trunk/lib/collections/arrays/arrays.js
@@ -0,0 +1,66 @@
/*************************************************************************/
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
if (!Array.prototype.product) {
Array.prototype.product = function(b) {
var a = this;
return $.map(
new Array(Math.max(this.length, a.length)),
function(e, i) {
var o = {};
o[a[i]] = b[i];
return o;
});
};
}
$.extend({
product: function(a, b) {
return $.map(
new Array(Math.max(this.length, a.length)),
function(e, i) {
var o = {};
o[a[i]] = b[i];
return o;
});
}
});
 
/*************************************************************************/
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
if (!Array.prototype.stride) {
Array.prototype.stride = function(s) {
return this.filter(function(e, i) {
return i % s === 0;
});
};
}
$.extend({
stride: function(a, s) {
return a.filter(function(e, i) {
return i % s === 0;
});
}
});
 
/*************************************************************************/
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
if (!Array.prototype.chunk) {
Array.prototype.chunk = function(n) {
if (!this.length) {
return [];
}
return [this.slice(0, n)]
.concat(this.slice(n).chunk(n));
};
}
$.extend({
chunk: function(a, n) {
if (!a.length) {
return [];
}
return [a.slice(0, n)]
.concat(a.slice(n).chunk(n));
}
});