was.js
/trunk/lib/collections/arrays/arrays.js |
@@ -1,6 +1,36 @@ |
/*************************************************************************/ |
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
/*************************************************************************/ |
function wasArrayToObject(a) { |
var o = {}; |
a.reduce(function(a, c, i) { |
i = Math.floor(i / 2); |
if (!a[i]) { |
a[i] = []; |
} |
a[i].push(c); |
return a; |
}, []).forEach(function(c, i, a) { |
o[c[0]] = c[1]; |
}, o); |
return o; |
} |
if (!Array.prototype.toObject) { |
Array.prototype.toObject = function() { |
return wasArrayToObject(this); |
}; |
} |
// jQuery |
if(typeof jQuery === 'function') { |
$.extend({ |
toObject: wasArrayToObject |
}); |
} |
|
|
/*************************************************************************/ |
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
/*************************************************************************/ |
function wasProduct(a, b) { |
var m = Math.max(a.length, b.length); |
var o = {}; |
@@ -109,6 +139,7 @@ |
product: wasProduct, |
stride: wasStride, |
chunk: wasChunk, |
equals: wasEquals |
equals: wasEquals, |
toObject: wasArrayToObject |
}; |
} |