was.js – Diff between revs 51 and 53
?pathlinks?
Rev 51 | Rev 53 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | /*************************************************************************/ |
1 | /*************************************************************************/ |
|
2 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
2 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
3 | /*************************************************************************/ |
3 | /*************************************************************************/ |
|
- | 4 | function wasArrayToObject(a) { |
||
- | 5 | var o = {}; |
||
- | 6 | a.reduce(function(a, c, i) { |
||
- | 7 | i = Math.floor(i / 2); |
||
- | 8 | if (!a[i]) { |
||
- | 9 | a[i] = []; |
||
- | 10 | } |
||
- | 11 | a[i].push(c); |
||
- | 12 | return a; |
||
- | 13 | }, []).forEach(function(c, i, a) { |
||
- | 14 | o[c[0]] = c[1]; |
||
- | 15 | }, o); |
||
- | 16 | return o; |
||
- | 17 | } |
||
- | 18 | if (!Array.prototype.toObject) { |
||
- | 19 | Array.prototype.toObject = function() { |
||
- | 20 | return wasArrayToObject(this); |
||
- | 21 | }; |
||
- | 22 | } |
||
- | 23 | // jQuery |
||
- | 24 | if(typeof jQuery === 'function') { |
||
- | 25 | $.extend({ |
||
- | 26 | toObject: wasArrayToObject |
||
- | 27 | }); |
||
- | 28 | } |
||
- | 29 | |
||
- | 30 | |
||
- | 31 | /*************************************************************************/ |
||
- | 32 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
- | 33 | /*************************************************************************/ |
||
4 | function wasProduct(a, b) { |
34 | function wasProduct(a, b) { |
|
5 | var m = Math.max(a.length, b.length); |
35 | var m = Math.max(a.length, b.length); |
|
6 | var o = {}; |
36 | var o = {}; |
|
7 | for(var i = 0; i < m; ++i) { |
37 | for(var i = 0; i < m; ++i) {> |
|
8 | o[a[i]] = b[i]; |
38 | < m; ++i) { o[a[i]] = b[i];> |
|
Line 107... | Line 137... | |||
107 | if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') { |
137 | < m; ++i) {if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') {> |
|
108 | module.exports.collections = { |
138 | < m; ++i) { module.exports.collections = {> |
|
109 | product: wasProduct, |
139 | < m; ++i) { product: wasProduct,> |
|
110 | stride: wasStride, |
140 | < m; ++i) { stride: wasStride,> |
|
111 | chunk: wasChunk, |
141 | < m; ++i) { chunk: wasChunk,> |
|
112 | equals: wasEquals |
142 | < m; ++i) { equals: wasEquals,> |
|
- | 143 | < m; ++i) { toObject: wasArrayToObject> |
||
113 | }; |
144 | < m; ++i) { };> |
|
114 | } |
145 | < m; ++i) {}> |